2024-06-11 18:27:55 +00:00
|
|
|
function get-resources {
|
|
|
|
|
|
|
|
|
|
param ( $pc )
|
|
|
|
|
|
|
|
|
|
$sBlock = {
|
2024-09-18 18:15:13 +00:00
|
|
|
Write-Progress -Activity "Getting resource data for $pc" -Status "Getting disk data" -PercentComplete 10 -ParentId 1
|
2024-06-11 18:27:55 +00:00
|
|
|
try {$win32_LogicalDisk = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" } catch {$win32_LogicalDisk = $null} #| Diskspace
|
|
|
|
|
$obj = New-Object -TypeName PSObject
|
|
|
|
|
|
|
|
|
|
# Get system information
|
2024-09-18 18:15:13 +00:00
|
|
|
Write-Progress -Activity "Getting resource data for $pc" -Status "Getting OS data" -PercentComplete 16 -ParentId 1
|
2024-06-11 18:27:55 +00:00
|
|
|
$sysInfo = Get-WmiObject -Class Win32_OperatingSystem
|
2024-09-18 18:15:13 +00:00
|
|
|
Write-Progress -Activity "Getting resource data for $pc" -Status "Getting processor data" -PercentComplete 33 -ParentId 1
|
2024-06-11 18:27:55 +00:00
|
|
|
$sysProc = Get-WmiObject -Class Win32_Processor
|
2024-09-18 18:15:13 +00:00
|
|
|
Write-Progress -Activity "Getting resource data for $pc" -Status "Getting memory data" -PercentComplete 50 -ParentId 1
|
2024-06-11 18:27:55 +00:00
|
|
|
$sysMem = Get-WmiObject -Class Win32_PhysicalMemory
|
|
|
|
|
|
2024-08-13 15:24:56 +00:00
|
|
|
$sysOS = $sysInfo.Caption
|
|
|
|
|
$sysVersion = $sysInfo.Version
|
|
|
|
|
if ($sysMem.Length) {
|
|
|
|
|
$sysTotalMem = 0
|
|
|
|
|
foreach ($mem in $sysMem) {
|
|
|
|
|
$sysTotalMem += $mem.Capacity
|
|
|
|
|
}
|
|
|
|
|
$sysTotalMem /= 1GB
|
|
|
|
|
} else {
|
|
|
|
|
$sysTotalMem = $sysMem.Capacity / 1GB
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 18:15:13 +00:00
|
|
|
Write-Progress -Activity "Getting resource data for $pc" -Status "Getting processor usage" -PercentComplete 66 -ParentId 1
|
2024-06-11 18:27:55 +00:00
|
|
|
# Get processor usage
|
|
|
|
|
$procUsage = [math]::Round((Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue)
|
|
|
|
|
|
2024-09-18 18:15:13 +00:00
|
|
|
Write-Progress -Activity "Getting resource data for $pc" -Status "Getting memory usage" -PercentComplete 83 -ParentId 1
|
2024-06-11 18:27:55 +00:00
|
|
|
# Get memory usage
|
2024-08-13 15:24:56 +00:00
|
|
|
$memUsage = [Math]::Round((1 - (Get-Counter '\Memory\Available MBytes').CounterSamples.CookedValue/($sysTotalMem*1GB/1MB))*100,1)
|
2024-06-11 18:27:55 +00:00
|
|
|
|
2024-09-18 18:15:13 +00:00
|
|
|
Write-Progress -Activity "Getting resource data for $pc" -Status "Getting network adapter data" -PercentComplete 100 -ParentId 1
|
2024-06-11 18:27:55 +00:00
|
|
|
# Get Physical Network Adapter information
|
|
|
|
|
$netAdapters = Get-NetAdapter -physical | Where-Object status -eq 'up'
|
|
|
|
|
|
|
|
|
|
#Free Harddrive Space
|
|
|
|
|
$CompFreeSpace = @([math]::Round($win32_LogicalDisk.FreeSpace / 1gb,2),[math]::Round($win32_LogicalDisk.Size / 1gb,2))
|
|
|
|
|
$freeDisk = $compFreeSpace[0]
|
|
|
|
|
$maxDisk = $compfreeSpace[1]
|
|
|
|
|
|
2024-08-13 15:24:56 +00:00
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'OS' -Value $sysOS
|
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'Version' -Value $sysVersion
|
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'TotalMem' -Value $sysTotalMem
|
2024-06-11 18:27:55 +00:00
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'MemUsage' -Value $memUsage
|
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'Processor' -Value $($sysProc.Name)
|
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'NumberOfCores' -Value $($sysProc.NumberOfCores)
|
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'ProcUsage' -Value $procUsage
|
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'NetAdapters' -Value $netAdapters
|
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'freeDisk' -Value $freeDisk
|
|
|
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'maxDisk' -Value $maxDisk
|
|
|
|
|
|
2024-09-18 18:15:13 +00:00
|
|
|
Write-Progress -Activity "Getting resource data for $pc" -Completed
|
2024-06-11 18:27:55 +00:00
|
|
|
return $obj
|
|
|
|
|
}
|
|
|
|
|
$output = @()
|
|
|
|
|
$output += Invoke-Command -ScriptBlock $sblock -ComputerName $pc -SessionOption (New-PSSessionOption -NoMachineProfile -OpenTimeout 45000) | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName
|
|
|
|
|
|
|
|
|
|
# Display system information
|
2024-08-13 15:44:59 +00:00
|
|
|
Write-Output "System Information:"
|
|
|
|
|
Write-Output "-------------------"
|
|
|
|
|
Write-Output "Computer Name: $pc"
|
|
|
|
|
Write-Output "Operating System: $($output.OS)"
|
|
|
|
|
Write-Output "Version: $($output.Version)"
|
|
|
|
|
Write-Output "Total Physical Memory: $($output.TotalMem) GB, Memory Usage: $($output.memUsage) %"
|
|
|
|
|
Write-Output "Processor: $($output.Name) $($output.NumberOfCores) cores, Processor Usage: $($output.procUsage)%"
|
|
|
|
|
Write-Output "Free Disk Space: $($output.freeDisk) GB / $($output.maxDisk) GB"
|
|
|
|
|
Write-Output "-------------------"
|
|
|
|
|
Write-Output "Physical Network Adapters:"
|
2024-06-11 18:27:55 +00:00
|
|
|
foreach ($netAdapter in $output.netAdapters) {
|
|
|
|
|
$speed = $netAdapter.Speed
|
|
|
|
|
if ($speed -gt 1000000000) {
|
|
|
|
|
$speed = "{0} Gbps" -f ($speed/1000000000)
|
2024-08-13 15:24:56 +00:00
|
|
|
} elseif($speed -gt 1000000){
|
|
|
|
|
$speed = "{0} Mbps" -f ($speed/1000000)
|
2024-06-11 18:27:55 +00:00
|
|
|
}
|
2024-08-13 15:44:59 +00:00
|
|
|
Write-Output "$($netAdapter.InterfaceDescription)`r`n`tType: $($netAdapter.name)`r`n`tLink Speed: $speed"
|
2024-06-11 18:27:55 +00:00
|
|
|
}
|
|
|
|
|
}
|