我是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
}}
答案 0 :(得分:0)
以下对我有用:
$ErrorActionPreference = "SilentlyContinue"
$ComputerCMID = Get-WmiObject –computer $ComputerName -class SoftwareLicensingService
$ErrorActionPreference = "Continue"