用于KMS报告的Powershell脚本

时间:2014-12-06 18:18:36

标签: powershell powershell-v2.0 powershell-ise

我是Powershell Scripting的新手。我想要完成的是编写一个脚本,该脚本将仅在KMS通道上查询WMI的KMS许可证状态,以及我希望将输出放入excel的机器的CMID。我写的脚本弹出一些我无法抑制的机器上的访问被拒绝错误。任何帮助,将不胜感激。

$AllADComputers = Get-ADComputer -searchbase "OU=CC3DELLS,DC=Sample,DC=com" 
ForEach ($Computers in $AllADComputers)
{
$ComputerName = $Computers.Name

if ((Test-Connection -computername $ComputerName -Quiet -ErrorAction SilentlyContinue) -eq $true) {


$ComputerCMID = Get-WmiObject –computer $ComputerName -class SoftwareLicensingService -ErrorVariable err -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Credential $Cred | Select-object ClientMachineID -ErrorAction SilentlyContinue 


Write-host "$ComputerName has the $ComputerCMID " 

} else {

Write-Host "$ComputerName is Down" -ForegroundColor Red
}}

1 个答案:

答案 0 :(得分:0)

以下对我有用:

$ErrorActionPreference = "SilentlyContinue"

$ComputerCMID = Get-WmiObject –computer $ComputerName -class SoftwareLicensingService

$ErrorActionPreference = "Continue"