-1

I am new to Powershell Scripting. I what I am trying to accomplish is to write a script that will query WMI for KMS Licence status on just the KMS channel and the CMID of the machine I would like the output to be put into excel. Also The script I am writing pops up with a access denied error on a few machines that I am unable to suppress. any help would be appreciated.

$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
}}
David Brabant
  • 41,623
  • 16
  • 83
  • 111
Bigjim
  • 1
  • 2
  • 2
  • this link should help with the excel part: http://blogs.technet.com/b/heyscriptingguy/archive/2014/01/10/powershell-and-excel-fast-safe-and-reliable.aspx – Paul Dec 06 '14 at 19:03

1 Answers1

0

The following worked for me:

$ErrorActionPreference = "SilentlyContinue"

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

$ErrorActionPreference = "Continue"
Micky Balladelli
  • 9,781
  • 2
  • 33
  • 31