Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $dc = 'domain.controller.FQDN'
- $wsou = 'OU=Workstations_OU,DC=domain,DC=local'
- $outfile = 'c:\path\to\ccmstatus.csv'
- $Session = New-PSSession -ComputerName $dc
- Invoke-Command -Session $Session -ScriptBlock {Import-Module ActiveDirectory -DisableNameChecking}
- Import-PSSession -Session $Session -Module ActiveDirectory | Out-Null
- $workstations = Get-ADComputer -Filter * -SearchBase $wsou | Select DNSHostName
- Remove-PSSession $Session
- $statuses = @()
- $Count = 0
- $SkippedCount = 0
- $ActiveCount = 0
- $InactiveCount = 0
- $NotFoundCount = 0
- $Total=$workstations.Count
- foreach ($workstation in $workstations)
- {
- if (Test-Connection -ComputerName $workstation.DNSHostName -Quiet -Count 1)
- {
- $status = Get-Service -ComputerName $workstation.DNSHostName -Name 'CcmExec' -ErrorAction:SilentlyContinue | Select Status, @{Name='Workstation';Expression={$workstation.DNSHostName}}
- if ($status)
- {
- if ($Status.Status -eq 'Running') {$ActiveCount++} else {$InactiveCount++}
- } else
- {
- $NotFoundCount++
- $status = New-Object PsObject -Property @{Workstation=($workstation.DNSHostName);Status='Not found'}
- }
- $statuses += $status
- } else
- {
- $SkippedCount++
- }
- $Count++
- $CurrentOperation = 'checked: '+$Count+'/'+$Total+', skipped: '+$SkippedCount+', active: '+$ActiveCount+', inactive: '+$InactiveCount+', not found: '+$NotFoundCount
- Write-Progress -Activity 'Checking SCCM client status' -CurrentOperation $CurrentOperation -PercentComplete ($Count/$Total*100)
- }
- $statuses | Export-Csv -Delimiter ';' -NoTypeInformation -Path $outfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement