2014-12-06 77 views
-1

我是Powershell脚本的新手。我试图完成的是编写一个脚本,该脚本将在KMS通道上查询WMI的KMS许可证状态,并且我希望将输出的CMID放入Excel中。此外,我正在写的脚本弹出一个访问被拒绝的错误在我无法压制的几台机器上。任何帮助,将不胜感激。KMS报告的PowerShell脚本

$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

此链接应与Excel的部分帮助:http://blogs.technet.com/b/heyscriptingguy/archive/2014/01/10/ PowerShell的和Excel的快捷安全,和reliable.aspx – Paul 2014-12-06 19:03:19

回答

0

以下为我工作:

$ErrorActionPreference = "SilentlyContinue" 

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

$ErrorActionPreference = "Continue"