Start-Transcript -path C:\Scripts\Log\wolreboot.txt $SiteCode = 'SCCM Site Code goes here' $CollectionName = 'Target collection name goes here' #Retrieve SCCM collection by name $Collection = GWMI -ComputerName $siteServer -NameSpace "ROOT\SMS\site_$SiteCode" -Class SMS_Collection | where {$_.Name -eq "$CollectionName"} #Retrieve members of collection $SMSMembers = GWMI -ComputerName $SiteServer -Namespace "ROOT\SMS\site_$SiteCode" -Query "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='$($Collection.CollectionID)' order by name" | select Name ForEach ($SMSMember in $SMSMembers){ If (test-connection $SMSMember.Name -Count 1 -quiet) { write-host $SMSMember.Name "Online" $name = $smsmember.name Start-Process Shutdown "-r -t 300 -m \\$name -c `"Initiating scheduled maintenance reboot. You have 5mins to save your before your PC will reboot`"" -NoNewWindow -Wait } Else { $a = (GWMI -ComputerName $siteServer -Class SMS_R_SYSTEM -Namespace root\sms\site_$SiteCode | where {$_.Name -eq $SMSMember.Name}).MACAddresses $a = $a -replace ':','' foreach ($mac in $a){ C:\Scripts\\wol.exe $mac write-host $SMSMember.name "WOL packet sent" $mac write-host `r`n} } } Stop-Transcript Exit