捐血一袋救人一命

2021年2月18日 星期四

使用 PowerShell 進行硬體資產調查

Windows 的 WMI, CIM 有很多資訊可以運用管理

例如軟硬體資產、系統資源效能、程式運作等

這次要做的是硬體資產調查,以前我有介紹使用 AIDA64 Business 來做資產調查,但這套軟體是要付費的。

所以不想要花錢,又要做到資產調查,就只好自己動作來

只要將 PowerShell 程式將資料寫入網芳檔案,使用群組政策,讓使用者開機就自動執行這個 PowerShell ,資料就會自動寫入檔案

$System = Get-CimInstance CIM_ComputerSystem
$BIOS = Get-CimInstance CIM_BIOSElement
$OS = Get-CimInstance CIM_OperatingSystem
$CPU = Get-CimInstance CIM_Processor
$HDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$EXTXT = "D:\Desktop\welp.txt"
Clear-Host

"`c`r" | Out-File -FilePath $EXTXT -Append -Encoding oem
get-wmiobject win32_networkadapterconfiguration -computer "." -filter "IPEnabled='True'" | Select DNSHostname,MACAddress,IPAddress | ForEach{
    "MAC Address: {1}, IP Address: {2}, IPV6: {3}" -f $_.DNSHostname, $_.MACAddress, $_.IPAddress[0], $_.IPAddress[1] | Out-File -FilePath $EXTXT -Append -Encoding oem
}
"Login User: {0}" -f $env:UserName | Out-File -FilePath $EXTXT -Append -Encoding oem
"User Domain: {0}" -f $env:UserDomain | Out-File -FilePath $EXTXT -Append -Encoding oem
"Host Name: {0}" -f $env:ComputerName | Out-File -FilePath $EXTXT -Append -Encoding oem
"Manufacturer: " + $System.Manufacturer | Out-File -FilePath $EXTXT -Append -Encoding oem
"Model: " + $System.Model | Out-File -FilePath $EXTXT -Append -Encoding oem
"CPU: " + $CPU.Name | Out-File -FilePath $EXTXT -Append -Encoding oem
"RAM: " + "{0:N2}" -f ($System.TotalPhysicalMemory/1GB) + "GB" | Out-File -FilePath $EXTXT -Append -Encoding oem
"HDD Capacity: "  + "{0:N2}" -f ($HDD.Size/1GB) + "GB" | Out-File -FilePath $EXTXT -Append -Encoding oem
"Operating System: " + $OS.caption | Out-File -FilePath $EXTXT -Append -Encoding oem
"VGA: {0}" -f (Get-WmiObject Win32_VideoController -ComputerName ".").description | Out-File -FilePath $EXTXT -Append -Encoding oem

0 意見: