Advertisement
dantpro

SCCM Client Agent Status Query

Oct 16th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://gallery.technet.microsoft.com/Determine-if-SCCM-Client-11c63381
  2. # http://blog-en.netvnext.com/2011/12/determine-if-sccm-client-is-stopped-on.html
  3.  
  4. # NAME: isAgentStopped.ps1
  5. # AUTHOR: Romano Jerez, NETvNext
  6. # DATE: 12/3/2011
  7. #
  8. # Description:
  9. # Remotely queries computers for status of SMS Agent Host service (CcmExec).
  10. # Queries are done on computers listed in a file pcList.txt (one per line).
  11. # No firewall should be blocking inbound ICMP and RPC traffic on computers.
  12. # You must run script using an account that has administrative rights on computers.
  13. #
  14. # Output:
  15. # Computers not accessible (i.e. offline) are listed in file offLine.txt.
  16. # Status of computers is recorded in agentStatus.txt.  File is comma-delimited
  17. # where one line per computer is used in format "computerName,Status".
  18. # ------------------------------------------------------------------------
  19.  
  20. $comp = get-content pcList.txt
  21. $strFileResults = "agentStatus.txt"
  22. $strOffLinePCs = "offLine.txt"
  23.  
  24. $skipped = @()
  25.  
  26. $comp | foreach {
  27.   $Global:currentpc = $_
  28.   if (Test-Connection $currentpc -Quiet -Count 1)
  29.  
  30.   {  
  31.     $status = get-service -ComputerName $currentpc | where-object { $_.Name -eq "CcmExec"} |
  32.                ForEach-Object { $_.status}
  33.  
  34.     $strLine = $currentpc + "," + $status
  35.     $strLine | Out-File $strFileResults -append
  36.     Write-Host $currentpc","$status
  37.    
  38.   }
  39.   else
  40.   {
  41.     $skipped += $currentpc
  42.   }
  43. }
  44.  
  45. $skipped | Out-File $strOffLinePCs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement