Advertisement
dantpro

SCCM Client Agent Status Query (AD)

Oct 16th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $dc = 'domain.controller.FQDN'
  2. $wsou = 'OU=Workstations_OU,DC=domain,DC=local'
  3. $outfile = 'c:\path\to\ccmstatus.csv'
  4.  
  5. $Session = New-PSSession -ComputerName $dc
  6. Invoke-Command -Session $Session -ScriptBlock {Import-Module ActiveDirectory -DisableNameChecking}
  7. Import-PSSession -Session $Session -Module ActiveDirectory | Out-Null
  8. $workstations = Get-ADComputer -Filter * -SearchBase $wsou | Select DNSHostName
  9. Remove-PSSession $Session
  10. $statuses = @()
  11. $Count = 0
  12. $SkippedCount = 0
  13. $ActiveCount = 0
  14. $InactiveCount = 0
  15. $NotFoundCount = 0
  16. $Total=$workstations.Count
  17. foreach ($workstation in $workstations)
  18. {
  19. if (Test-Connection -ComputerName $workstation.DNSHostName -Quiet -Count 1)
  20.  {
  21.   $status = Get-Service -ComputerName $workstation.DNSHostName -Name 'CcmExec' -ErrorAction:SilentlyContinue | Select Status, @{Name='Workstation';Expression={$workstation.DNSHostName}}
  22.   if ($status)
  23.   {
  24.    if ($Status.Status -eq 'Running') {$ActiveCount++} else {$InactiveCount++}
  25.   } else
  26.   {
  27.    $NotFoundCount++
  28.    $status = New-Object PsObject -Property @{Workstation=($workstation.DNSHostName);Status='Not found'}
  29.   }
  30.   $statuses += $status
  31.  } else
  32.  {
  33.   $SkippedCount++
  34.  }
  35.  $Count++
  36.  $CurrentOperation = 'checked: '+$Count+'/'+$Total+', skipped: '+$SkippedCount+', active: '+$ActiveCount+', inactive: '+$InactiveCount+', not found: '+$NotFoundCount
  37.  Write-Progress -Activity 'Checking SCCM client status' -CurrentOperation $CurrentOperation -PercentComplete ($Count/$Total*100)
  38. }
  39. $statuses | Export-Csv -Delimiter ';' -NoTypeInformation -Path $outfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement