-
Notifications
You must be signed in to change notification settings - Fork 0
Powershell scripts
Didier Prolhac edited this page Aug 3, 2017
·
2 revisions
PS H:\> Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-object -Property LastBootUpTime
LastBootUpTime
--------------
20170802050008.125600+120
PS H:\> Get-WmiObject -Class Win32_Processor -ComputerName . | Select-object -Property LoadPercentage
LoadPercentage
--------------
4
PS H:\> Get-WmiObject -Class Win32_ComputerSystem -ComputerName . | Select-object -Property TotalPhysicalMemory
TotalPhysicalMemory
-------------------
17054662656
PS H:\> Get-WmiObject -Class Win32_OperatingSystem -ComputerName . | Select-object -Property TotalVirtualMemorySize,TotalVisibleMemorySize,FreePhysicalMemory,FreeSpaceInPagingFiles,FreeVirtualMemory
TotalVirtualMemorySize : 33308028
TotalVisibleMemorySize : 16654944
FreePhysicalMemory : 11680540
FreeSpaceInPagingFiles : 16654944
FreeVirtualMemory : 27980172
PS H:\> Get-WmiObject -Class Win32_LogicalDisk -ComputerName . | Select-object -Property Name,DriveType,Size,FreeSpace
Name DriveType Size FreeSpace
---- --------- ---- ---------
C: 3 255534821376 170625495040
H: 4 399691089346560 145044164018688
P: 4 125829115904 102334033920
S: 4 125829115904 102334033920
Return an XML file :
$oResponse = New-Object –TypeName PSObject
$uptime = gwmi Win32_OperatingSystem | select LastBootUpTime
$oResponse | Add-Member –MemberType NoteProperty -Name Uptime -Value $uptime.LastBootUpTime
$load = gwmi Win32_Processor | select LoadPercentage
$oResponse | Add-Member –MemberType NoteProperty -Name Load_1m -Value $load.LoadPercentage
$oResponse | Add-Member –MemberType NoteProperty -Name Load_5m -Value $load.LoadPercentage
$oResponse | Add-Member –MemberType NoteProperty -Name Load_15m -Value $load.LoadPercentage
$computerMem = gwmi Win32_ComputerSystem | select TotalPhysicalMemory
$computerMem.TotalPhysicalMemory = $computerMem.TotalPhysicalMemory / 1024
$oResponse | Add-Member –MemberType NoteProperty -Name PhysicalMem_Total -Value $computerMem.TotalPhysicalMemory
$osMem = gwmi Win32_OperatingSystem | select TotalVirtualMemorySize,TotalVisibleMemorySize,FreePhysicalMemory,FreeVirtualMemory
$oResponse | Add-Member –MemberType NoteProperty -Name PhysicalMem_Free -Value $osMem.FreePhysicalMemory
$oResponse | Add-Member –MemberType NoteProperty -Name VirtualMem_Total -Value $osMem.TotalVirtualMemorySize
$oResponse | Add-Member –MemberType NoteProperty -Name VirtualMem_Free -Value $osMem.FreeVirtualMemory
$oResponse | Add-Member –MemberType NoteProperty -Name VisibleMem_Total -Value $osMem.TotalVisibleMemorySize
$arDisks = gwmi Win32_LogicalDisk | select Name,DriveType,Size,FreeSpace
foreach($disk in $arDisks) {
$oResponse | Add-Member –MemberType NoteProperty -Name "Disk_$($disk.Name)_Total" -Value $disk.Size
$oResponse | Add-Member –MemberType NoteProperty -Name "Disk_$($disk.Name)_Free" -Value $disk.FreeSpace
}
Write-Output $oResponse | convertTo-Xml -As String -NoTypeInformation
$sBody = Write-Output $oResponse | convertTo-Xml -As String -NoTypeInformation
Invoke-RestMethod https://[]/data -Body $sBody -Method POST