-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRemoteWmiInfo Revengeance.ps1
219 lines (165 loc) · 6.35 KB
/
RemoteWmiInfo Revengeance.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Refer to https://www.behance.net/gallery/125670705/Remote-WMI-Info
# and https://www.behance.net/gallery/125673977/Remote-Mass-Info
function _UpdateLog {
param (
[Parameter(
ValueFromPipeline
)]
[string]$message,
[switch]$status
)
$currentText = $form.rtfLog.Text
$lines = $currentText -split "`r`n"
$newLineNumber = $lines.Count + 1
$currentTime = Get-Date -DisplayHint Time -Format "HH:mm:ss"
$logMessage = "{0,-2}: {1}`t{2}" -f $newLineNumber, $currentTime, $message
if ($currentText) {
$form.rtfLog.AppendText("`r`n$logMessage")
} else {
$form.rtfLog.AppendText($logMessage)
}
$form.rtfLog.ScrollToCaret()
if($status) {
$form.StatusLabel1.Text = $currentTime
$form.StatusLabel2.Text = $message
}
}
# assume the device is online
function _GetApps($ComputerName, $Session) {
$AppSplat = @{
ScriptBlock = {
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*,HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
? { $_.DisplayName -and $_.DisplayVersion -and !$_.SystemComponent}
}
}
if($Session) {
$AppSplat.Session = $Session
} elseif($ComputerName) {
$AppSplat.ComputerName = $ComputerName
}
$InstalledApps = Invoke-Command @AppSplat | sort DisplayName
return $InstalledApps
}
$form_Closing = {
$this.comboHostName.Items.foreach{
New-ItemProperty -Path "HKCU:\Software\THR\RemoteWmiInfo" -Name $_ -Value 1 -Force
}
}
$form_Load = {
$this.comboHostName.Items.Clear()
$this.comboHostName.Items.AddRange((Get-ItemProperty "HKCU:\Software\THR\RemoteWmiInfo").PSObject.Properties.where{$_.Value -eq 1}.Name)
$this.comboHostName.Text = $env:COMPUTERNAME
}
$btnAppsRefresh_Click = {
$this.Enabled = $false
$form.tabControl1.SelectedTab = $form.tabLog
$form.tabLog.Select()
$ComputerName = $form.comboHostName.Text
if(-not (Test-Connection $ComputerName)) {
_updateLog -message "Failed to connect to $ComputerName" -status
$this.Enabled = $true
Return
}
$form.tabControl1.SelectedTab = $form.tabSoftware
$form.tabSoftware.Select()
_updateLog -message "Refreshing installed applications" -status
$InstalledApps = _GetApps -ComputerName $ComputerName
$form.listApps.Items.Clear()
foreach($app in $InstalledApps) {
$item = New-Object Windows.Forms.ListViewItem($app.DisplayName)
$item.SubItems.Add($app.DisplayVersion)
$item.SubItems.Add($app.Publisher)
$item.SubItems.Add($app.InstallDate)
$form.listApps.Items.Add($item)
}
$this.Enabled = $true
}
$linkOS_LinkClicked = {
scb $form.txtOS
}
$linkBIOSRam_LinkClicked = {
"{0}, {1}" -f $form.txtCompBIOS.Text, $form.txtCompRAM.Text | scb
}
$linkCPUSpeed_LinkClicked = {
"{0}, {1}" -f $form.txtCompCPU.Text, $form.txtCompCPUSp.Text | scb
}
$linkSerialAsset_LinkClicked = {
"{0}, {1}" -f $form.txtCompSerial.Text, $form.txtCompAsset.Text | scb
}
$linkMakeModel_LinkClicked = {
"{0}, {1}" -f $form.txtCompMake.Text, $form.txtCompModel.Text | scb
}
$btnRemote_Click = {
if(Test-Path "$env:SMS_ADMIN_UI_PATH\CmRcViewer.exe") {
$RemotePath = "$env:SMS_ADMIN_UI_PATH\CmRcViewer.exe"
}
if($RemotePath) {
Start-Process $RemotePath -Args @($form.comboHostName.Text)
} else {
_updateLog -message "Failed to find Remote Control Viewer" -status
}
}
$tabNetwork_Click = {
# TODO: Update fields on-demand?
}
$btnReset_Click = {
$form.comboHostName.Text = $env:COMPUTERNAME
}
$btnConnect_Click = {
if(!$form.comboHostName.Text) {
$form.StatusLabel1.Text = [datetime]::Now.TimeOfDay
$form.StatusLabel2.Text = "Please enter a hostname"
Return
}
$ComputerName = $form.comboHostname.Text
_updateLog -message "Connecting to $ComputerName" -status
$form.btnConnect.Enabled = $false
if(-not (test-connection -ComputerName $ComputerName -Count 1 -Quiet)) {
_updateLog -message "Failed to connect to $ComputerName" -status
$form.btnConnect.Enabled = $true
$form.btnRemote.Enabled = $false
$form.btnRefreshApps.Enabled = $false
Return
}
_updateLog -message "Connected to $ComputerName" -status
$form.btnRemote.Enabled = $true
$form.btnRefreshApps.Enabled = $true
# add device to connection history
New-ItemProperty -Path "HKCU:\Software\THR\RemoteWmiInfo" -Name $ComputerName -Value 1 -Force
$CIMSession = New-CimSession -ComputerName $ComputerName -Name RemoteWmiInfo -ea SilentlyContinue
$PSSession = New-PSSession -ComputerName $ComputerName -Name RemoteWmiInfo -ea SilentlyContinue
#region update General tab
$CSProperties = Get-CimInstance Win32_ComputerSystem -CimSession $CIMSession
$BIOSProperties = Get-CimInstance Win32_BIOS -CimSession $CIMSession
$CSPProperties = Get-CimInstance win32_computerSystemProduct -CimSession $CIMSession
$CSProcessor = Get-CimInstance Win32_ComputerSystemProcessor -CimSession $CIMSession
$W32Processor = Get-CimInstance Win32_Processor -CimSession $CIMSession
_updateLog -message "Getting hardware info"
$form.tabControl1.SelectedTab = $form.tabLog
$form.tabLog.Select()
$form.txtCompMake.Text = $CSProperties.Manufacturer
$form.txtCompModel.Text = $CSProperties.Model
$form.txtCompSerial.Text = $BIOSProperties.SerialNumber
$form.txtCompAsset.Text = $CSPProperties.IdentifyingNumber
$form.txtCompCPU.Text = $W32Processor.Name
$form.txtCompCPUSp.Text = $W32Processor.MaxClockSpeed[0]
#endregion update General tab
#region get software
_updateLog -message "Getting installed applications"
$InstalledApps = _GetApps -Session $PSSession
$form.listApps.Items.Clear()
foreach($app in $InstalledApps) {
$item = New-Object Windows.Forms.ListViewItem($app.DisplayName)
$item.SubItems.Add($app.DisplayVersion)
$item.SubItems.Add($app.Publisher)
$item.SubItems.Add($app.InstallDate)
$form.listApps.Items.Add($item)
}
#endregion get software
$CIMSession | Remove-CimSession
$form.tabControl1.SelectedTab = $form.tabGeneral
$form.tabGeneral.Select()
$form.btnConnect.Enabled = $true
}
. (Join-Path $PSScriptRoot 'RemoteWmiInfo Revengeance.designer.ps1')
$form.ShowDialog()