我正在尝试编写一份健康报告,以便更轻松地查看我控制下的所有电脑的概览。
这是我到目前为止所拥有的:
$ErrorActionPreference = "silentlycontinue"
$ComputerList = get-content C:\Users\Administrator\Desktop\DavidsScripts\FloorHealth\input.txt
$collectionVariable = New-Object System.Collections.ArrayList
ForEach ($Computer in $ComputerList) {
# Create temp object
$temp = New-Object System.Object
# Add members to temp object
$temp | Add-Member -MemberType NoteProperty -Name "Keys" (Get-WmiObject -query ‘select * from
SoftwareLicensingService’).OA3xOriginalProductKey
$temp | Add-Member -MemberType NoteProperty -Name "PC" (Get-WMIObject -ComputerName $Computer
Win32_ComputerSystem | Select-Object -ExpandProperty name)
$temp | Add-Member -MemberType NoteProperty -Name "IP" -Value $Computer
$temp | Add-Member -MemberType NoteProperty -Name "MACAddress" -Value (gwmi -ComputerName $Computer
-Class Win32_NetworkAdapterConfiguration | where {$_.IPAddress -like "$Computer"}).MACAddress
$temp | Add-Member -MemberType NoteProperty -Name "Ram" (Get-WMIObject -class Win32_PhysicalMemory -
ComputerName $Computer | Measure-Object -Property capacity -Sum | % {[Math]::Round(($_.sum /
1GB),2)})
$temp | Add-Member -MemberType NoteProperty -Name "Firewall" -Value ((netsh -r $Computer advfirewall
show currentprofile state)[3] -replace 'State' -replace '\s')
# Add the temp object to ArrayList
$collectionVariable.Add($temp)
}
Write-Output $collectionVariable
$collectionVariable | Export-Excel -now
C:\Users\Administrator\Desktop\DavidsScripts\FloorHealth\floorhealth.xlsx
我很难获得 Windows 产品密钥。(很抱歉前 1 的格式无法将较长的行保留在自己的行上)
我编写了第二个脚本,但不太确定如何将它添加到我现有的而不只是将代码粘贴到其中。我可以调用它并从我的健康报告中运行脚本,然后只拆分产品密钥,然后将其发送到 excel 中吗?
($targets = get-content C:\Users\Administrator\Desktop\DavidsScripts\FloorHealth\input.txt)
$hklm = 2147483650
$regPath = "Software\Microsoft\Windows NT\CurrentVersion"
$regValue = "DigitalProductId"
Foreach ($target in $targets) {
$productKey = $null
$win32os = $null
$wmi = [WMIClass]"\\$target\root\default:stdRegProv"
$data = $wmi.GetBinaryValue($hklm,$regPath,$regValue)
$binArray = ($data.uValue)[52..66]
$charsArray =
"B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9"
## decrypt base24 encoded binary data
For ($i = 24; $i -ge 0; $i--) {
$k = 0
For ($j = 14; $j -ge 0; $j--) {
$k = $k * 256 -bxor $binArray[$j]
$binArray[$j] = [math]::truncate($k / 24)
$k = $k % 24
}
$productKey = $charsArray[$k] + $productKey
If (($i % 5 -eq 0) -and ($i -ne 0)) {
$productKey = "-" + $productKey
}
}
$obj = New-Object Object
$obj | Add-Member Noteproperty ProductKey -value $productkey
$obj
}