-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputerStats.ps1
More file actions
executable file
·33 lines (30 loc) · 1.23 KB
/
ComputerStats.ps1
File metadata and controls
executable file
·33 lines (30 loc) · 1.23 KB
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
cls
$logFile = "C:\test\computerInfo.txt"
function Get-ComputerStats {
param(
[Parameter(Mandatory=$true, Position=0,
ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[ValidateNotNull()]
[string]$C#omputerName
)
process {
$date = Get-Date -Format g
#foreach ($c in $ComputerName) {
$avg = Get-WmiObject win32_processor -computername $c |
Measure-Object -property LoadPercentage -Average |
Foreach {$_.Average}
$mem = Get-WmiObject win32_operatingsystem -ComputerName $c |
Foreach {"{0:N2}" -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize)}
$free = Get-WmiObject Win32_Volume -ComputerName $c -Filter "DriveLetter = 'C:'" |
Foreach {"{0:N2}" -f (($_.FreeSpace / $_.Capacity)*100)}
return "$date|$c|$avg|$mem|$free|"
#}
}
}
if(!(Test-Path $logFile)){
New-Item -Path $logFile -ItemType file
}
if((Get-Content $logFile) -eq $Null){
Add-Content -Path $logFile -value "Date|ComputerName|CPUAverage|MemoryUsage|FreeDiskSpace"
}
Get-ComputerStats('localhost')|Add-Content $logFile