dantpro icon

SCCM Client Agent Status Query

dantpro | PRO | 10/16/14 09:27:23 AM UTC | 0 ⭐ | 567 👁️ | Never ⏰ | []
PowerShell |

1.46 KB

|

None

|

0 👍

/

0 👎

# https://gallery.technet.microsoft.com/Determine-if-SCCM-Client-11c63381
# http://blog-en.netvnext.com/2011/12/determine-if-sccm-client-is-stopped-on.html
 
# NAME: isAgentStopped.ps1
# AUTHOR: Romano Jerez, NETvNext
# DATE: 12/3/2011
#
# Description:
# Remotely queries computers for status of SMS Agent Host service (CcmExec).
# Queries are done on computers listed in a file pcList.txt (one per line).
# No firewall should be blocking inbound ICMP and RPC traffic on computers.
# You must run script using an account that has administrative rights on computers.
#
# Output:
# Computers not accessible (i.e. offline) are listed in file offLine.txt.
# Status of computers is recorded in agentStatus.txt.  File is comma-delimited
# where one line per computer is used in format "computerName,Status".
# ------------------------------------------------------------------------ 
 
$comp = get-content pcList.txt
$strFileResults = "agentStatus.txt"
$strOffLinePCs = "offLine.txt"
 
$skipped = @()
 
$comp | foreach {
  $Global:currentpc = $_
  if (Test-Connection $currentpc -Quiet -Count 1)
 
  {  
    $status = get-service -ComputerName $currentpc | where-object { $_.Name -eq "CcmExec"} | 
               ForEach-Object { $_.status}
 
    $strLine = $currentpc + "," + $status
    $strLine | Out-File $strFileResults -append
    Write-Host $currentpc","$status
    
  }
  else
  {
    $skipped += $currentpc
  }
}
 
$skipped | Out-File $strOffLinePCs

Comments