Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Start-CCMRerunAdvertisement { Start-CCMRerunAdvertisement -ComputerName $_ -AdvertisementID UNC53487 }
- workflow foreachrerun {
- param([string[]]$computers)
- foreach –parallel ($computer in $computers) {
- Start-CCMRerunAdvertisement –ComputerName $Computer -AdvertisementID UNC53487
- }
- }
- $ComputerList = Get-Content "c:\computerlist.txt"
- function Send-Email {
- # param (
- [Parameter(Mandatory=$true)]
- [String]$Body,
- [String]$ComputerName
- # )
- Send-MailMessage -From “admin@domain.com" -To “user@domain.com" -SMTPServer mail.domain.com -Subject “$($computername) is OFFLINE " # -Body $Body
- }
- function Test-Running {
- param (
- [Parameter(Mandatory=$true)]
- [System.String]$ComputerName
- )
- $processList = @'
- "Name", "Expected", "Running"
- "cmd", "1", "0"
- "powershell", "1", "0"
- "OfficeClickToRun", "2", "0"
- '@ | ConvertFrom-Csv | ForEach-Object {$_.Expected = [int]$_.Expected; $_}
- $splat = @{}
- $splat['ComputerName'] = $computerName
- Write-Host "Testing processes on $($computerName)" -ForegroundColor Yellow
- Do {
- $processList | ForEach-Object {
- $_.Running = @(Get-Process $_.Name @splat -ErrorAction SilentlyContinue).Count
- }
- ($processList | Format-Table -AutoSize | Out-String).Split("`r`n", [StringSplitOptions]::RemoveEmptyEntries) | Write-Host
- If ($running = @($processList | Where-Object {$_.Running -ge $_.Expected}).Count) {
- Start-Sleep -Seconds 5
- }
- } Until (-not $running)
- Restart-Computer -Computer $Computername -Force
- return 0
- }
- function Test-MyConnection {
- param (
- [Parameter(Mandatory=$true)]
- [System.String]
- $ComputerName
- )
- if (Test-Connection $computername -Quiet -Count 2) {
- Write-Host "Ping successful on $($computerName)" -ForegroundColor Green
- Test-Running -ComputerName $ComputerName
- }
- else {
- send-email $computername -ComputerName $computername -body $processlistOP
- Write-Host $($computerName) "is Offline." -ForegroundColor Red
- }
- }
- Test-MyConnection -ComputerName $computername
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement