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
}}