-
Notifications
You must be signed in to change notification settings - Fork 1
/
tool.ps1
226 lines (123 loc) · 4.65 KB
/
tool.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
220
221
222
223
224
225
226
#Add in the frameworks so that we can create the WPF GUI
Add-Type -AssemblyName presentationframework, presentationcore
#Create empty hashtable into which we will place the GUI objects
$wpf = @{ }
#Grab the content of the Visual Studio xaml file as a string
$inputXML = Get-Content -Path "D:\projects\powershell\repo\WpfApp2\WpfApp2\MainWindow.xaml"
#clean up xml there is syntax which Visual Studio 2015 creates which PoSH can't understand
$inputXMLClean = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace 'x:Class=".*?"','' -replace 'd:DesignHeight="\d*?"','' -replace 'd:DesignWidth="\d*?"',''
#change string variable into xml
[xml]$xaml = $inputXMLClean
#read xml data into xaml node reader object
$reader = New-Object System.Xml.XmlNodeReader $xaml
#create System.Windows.Window object
$tempform = [Windows.Markup.XamlReader]::Load($reader)
#select each named node using an Xpath expression.
$namedNodes = $xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]")
#add all the named nodes as members to the $wpf variable, this also adds in the correct type for the objects.
$namedNodes | ForEach-Object {$wpf.Add($_.Name, $tempform.FindName($_.Name))}
cls
$wpf
# Memory issue
$wpf.Memory_button.Add_Click({
$wpf.output.Text = cls
<#
If (-NOT ([string]::IsNullOrEmpty($wpf.Input.Text))) {
Write-Verbose "Gathering processes from $Computername" -Verbose
$Computername = $wpf.Input.text
Try { #>
#This will list all the process with high memory in descending order
$Processes = Invoke-Command -ScriptBlock {Get-Process | Sort-Object -property 'WS' -Descending} #-ComputerName $Computername
$Processes | Out-GridView
#This will give current used memory in %
$Total_Memory = Invoke-Command -ScriptBlock {gwmi -Class win32_operatingsystem |
Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}} #-ComputerName $ComputerName.Name
$wpf.output.Text = ($Total_Memory | Out-String)
<#
}
Catch {
Write-Warning $_
}
}
#>
})
#CPU issue
$wpf.CPU_button.Add_Click({
$wpf.output.Text = cls
<#
If (-NOT ([string]::IsNullOrEmpty($wpf.Input.Text))) {
Write-Verbose "Gathering processes from $Computername" -Verbose
$Computername = $wpf.Input.text
Try { #>
#This will list all the process with high CPU in descending order
$Processes = Invoke-Command -ScriptBlock {Get-Process | Sort-Object -property 'CPU' -Descending}# -ComputerName $ComputerName
$Processes | Out-GridView
#This will give current used memory in %
$Total_CPU = Invoke-Command -ScriptBlock {gwmi win32_processor | Measure-Object -property LoadPercentage -Average | Select Average} #-ComputerName $ComputerName.Name
$wpf.output.Text = ($Total_CPU | Out-String)
<#
}
Catch {
Write-Warning $_
}
}
#>
})
#Service issue:check service status
$wpf.check_service.Add_Click({
$wpf.output.Text = cls
<#
If (-NOT ([string]::IsNullOrEmpty($wpf.Input.Text))) {
Write-Verbose "Gathering processes from $Computername" -Verbose
$Computername = $wpf.Input.text
Try { #>
$service = $wpf.input_service.Text
#Current status of the service
$ser1 = Invoke-Command -ScriptBlock {Get-Service -DisplayName $service} #-ComputerName $ComputerName.Name
$ser1 | Out-Gridview
<#}
Catch {
Write-Warning $_
}
}
#>
})
#Service issue:start service
$wpf.start_service.Add_Click({
$wpf.output.Text = cls
<#
If (-NOT ([string]::IsNullOrEmpty($wpf.Input.Text))) {
Write-Verbose "Gathering processes from $Computername" -Verbose
$Computername = $wpf.Input.text
Try { #>
$service = $wpf.input_service.Text
#stop current service
$ser2 = Invoke-Command -ScriptBlock {Start-Service -DisplayName $service -Verbose} #-ComputerName $ComputerName.Name
$ser3 = Invoke-Command -ScriptBlock {Get-Service -DisplayName $service} #-ComputerName $ComputerName.Name
$ser3 | Out-Gridview
<#}
Catch {
Write-Warning $_
}
}
#>
})
#Disk Space issue
$wpf.Disk_button.Add_Click({
$wpf.output.Text = cls
<#
If (-NOT ([string]::IsNullOrEmpty($wpf.Input.Text))) {
Write-Verbose "Gathering processes from $Computername" -Verbose
$Computername = $wpf.Input.text
Try { #>
#check Disk space
$disk = Invoke-Command -ScriptBlock {gwmi -Class Win32_LogicalDisk | Select-Object DeviceID, @{n="free"; e ={“{0:N2}” -f (($_.Freespace/$_.size)*100)}}} #-ComputerName $ComputerName.Name
$disk | Out-Gridview
<#}
Catch {
Write-Warning $_
}
}
#>
})
$wpf.common_tool.ShowDialog() | Out-Null