Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. #ERROR REPORTING ALL
  2. Set-StrictMode -Version latest
  3.  
  4. #----------------------------------------------------------
  5. #STATIC VARIABLES
  6. #----------------------------------------------------------
  7. $SCRIPT_PARENT = Split-Path -Parent $MyInvocation.MyCommand.Definition
  8.  
  9. #----------------------------------------------------------
  10. #FUNCTION RepairSCCM
  11. #----------------------------------------------------------
  12. Function Repair_SCCM
  13. {
  14. Write-Host "[INFO] Get the list of computers from the input file and store it in an array."
  15. $arrComputer = Get-Content ($SCRIPT_PARENT + "\input.txt")
  16. Foreach ($strComputer In $arrComputer)
  17. {
  18. #Put an asterisk (*) in front of the lines that need to be skipped in the input file.
  19. If ($strComputer.substring(0,1) -ne "*")
  20. {
  21. Write-Host "[INFO] Starting trigger script for $strComputer."
  22. Try
  23. {
  24. $getProcess = Get-Process -Name ccmrepair* -ComputerName $strComputer
  25. If ($getProcess)
  26. {
  27. Write-Host "[WARNING] SCCM Repair is already running. Script will end."
  28. Exit 1
  29. }
  30. Else
  31. {
  32. Write-Host "[INFO] Connect to the WMI Namespace on $strComputer."
  33. $SMSCli = [wmiclass] "\\$strComputer\root\ccm:sms_client"
  34. Write-Host "[INFO] Trigger the SCCM Repair on $strComputer."
  35. # The actual repair is put in a variable, to trap unwanted output.
  36. $repair = $SMSCli.RepairClient()
  37. Write-Host "[INFO] Successfully connected to the WMI Namespace and triggered the SCCM Repair on $strComputer."
  38. ########## START - PROCESS / PROGRESS CHECK AND RUN
  39. # Comment the lines below if it is unwanted to wait for each repair to finish and trigger multiple repairs quickly.
  40. Write-Host "[INFO] Wait (a maximum of 7 minutes) for the repair to actually finish."
  41. For ($i = 0; $i -le 470; $i++)
  42. {
  43. $checkProcess = Get-Process -Name ccmrepair* -ComputerName $strComputer
  44. Start-Sleep 1
  45. Write-Progress -Activity "Repairing client $strComputer ..." -Status "Repair running for $i seconds ..."
  46.  
  47. If ($checkProcess -eq $Null)
  48. {
  49. Write-Host "[INFO] SCCM Client repair ran for $i seconds."
  50. Write-Host "[INFO] SCCM Client repair process ran successfully on $strComputer."
  51. Write-Host "[INFO] Check \\$strComputer\c$\Windows\SysWOW64\CCM\Logs\repair-msi%.log to make sure it was successful."
  52. }
  53. ElseIf ($i -eq 470)
  54. {
  55. Write-Host "[ERROR] Repair ran for more than 7 minutes. Script will end and process will be stopped."
  56. Invoke-Command -Computer $strComputer { Get-Process -Name ccmrepair* | Stop-Process -Force }
  57. Exit 1
  58. }
  59. }
  60. ########## END - PROCESS / PROGRESS CHECK AND RUN
  61.  
  62. }
  63. }
  64. Catch
  65. {
  66. Write-Host "[WARNING] Either the WMI Namespace connect or the SCCM Repair trigger returned an error."
  67. Write-Host "[WARNING] This is most likely caused, because there is already a repair trigger running."
  68. Write-Host "[WARNING] Wait a couple of minutes and try again."
  69. # If the script keeps throwing errors, the WMI Namespace on $strComputer might be corrupt.
  70. }
  71. }
  72. }
  73. }
  74. # RUN SCRIPT
  75. Repair_SCCM
  76. #Finished
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement