Advertisement
tseanlaws

MFEE

Oct 15th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. Function Start-CCMRerunAdvertisement { Start-CCMRerunAdvertisement -ComputerName $_ -AdvertisementID UNC53487 }
  2.  
  3. workflow foreachrerun {
  4. param([string[]]$computers)
  5. foreach –parallel ($computer in $computers) {
  6. Start-CCMRerunAdvertisement –ComputerName $Computer -AdvertisementID UNC53487
  7. }
  8. }
  9.  
  10. $ComputerList = Get-Content "c:\computerlist.txt"
  11.  
  12. function Send-Email {
  13. # param (
  14. [Parameter(Mandatory=$true)]
  15. [String]$Body,
  16. [String]$ComputerName
  17. # )
  18. Send-MailMessage -From “admin@domain.com" -To “user@domain.com" -SMTPServer mail.domain.com -Subject “$($computername) is OFFLINE " # -Body $Body
  19.  
  20. }
  21.  
  22. function Test-Running {
  23. param (
  24. [Parameter(Mandatory=$true)]
  25. [System.String]$ComputerName
  26. )
  27. $processList = @'
  28. "Name", "Expected", "Running"
  29. "cmd", "1", "0"
  30. "powershell", "1", "0"
  31. "OfficeClickToRun", "2", "0"
  32. '@ | ConvertFrom-Csv | ForEach-Object {$_.Expected = [int]$_.Expected; $_}
  33. $splat = @{}
  34. $splat['ComputerName'] = $computerName
  35. Write-Host "Testing processes on $($computerName)" -ForegroundColor Yellow
  36. Do {
  37. $processList | ForEach-Object {
  38. $_.Running = @(Get-Process $_.Name @splat -ErrorAction SilentlyContinue).Count
  39. }
  40. ($processList | Format-Table -AutoSize | Out-String).Split("`r`n", [StringSplitOptions]::RemoveEmptyEntries) | Write-Host
  41. If ($running = @($processList | Where-Object {$_.Running -ge $_.Expected}).Count) {
  42. Start-Sleep -Seconds 5
  43. }
  44. } Until (-not $running)
  45.  
  46. Restart-Computer -Computer $Computername -Force
  47.  
  48. return 0
  49. }
  50.  
  51. function Test-MyConnection {
  52. param (
  53. [Parameter(Mandatory=$true)]
  54. [System.String]
  55. $ComputerName
  56. )
  57. if (Test-Connection $computername -Quiet -Count 2) {
  58. Write-Host "Ping successful on $($computerName)" -ForegroundColor Green
  59. Test-Running -ComputerName $ComputerName
  60. }
  61. else {
  62. send-email $computername -ComputerName $computername -body $processlistOP
  63. Write-Host $($computerName) "is Offline." -ForegroundColor Red
  64. }
  65. }
  66.  
  67. Test-MyConnection -ComputerName $computername
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement