Guest User

reinstall SMS Client

a guest
May 16th, 2015
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###########################################################################################
  2. #
  3. #
  4. # The script's intended purpose is to completely un-install and re-install the SCCM Client.
  5. # Written By: Chris Beattie
  6. #
  7. ###########################################################################################
  8.  
  9. If ($PSVersionTable.PSVersion.Major -gt 3) {Write-Host "You have PowerShell Version 4 or higher - you should be fine to run this script"}
  10. elseif ($PSVersionTable.PSVersion.Major -eq 3) {Write-Host "You have PowerShell Version 3 - you should be fine to run this script"}
  11. elseif ($PSVersionTable.PSVersion.Major -eq 2) {Write-Host "You have PowerShell Version 2 - you may have issues running this script"}
  12. elseif ($PSVersionTable.PSVersion.Major -eq 1) {Write-Host "You have PowerShell Version 1 - time to upgrade this script is not going to work for you"}
  13.  
  14. Start-sleep -seconds 2
  15.  
  16. # define working directory of the script based on powershell version that is hosting the script
  17. if($PSVersionTable.PSVersion.Major -lt 3){$WorkingDirectory = split-path -parent $MyInvocation.MyCommand.Definition}
  18. else{$WorkingDirectory = $PSScriptRoot}
  19.  
  20. # define variables
  21. $Domain = $env:USERDNSDOMAIN
  22. $WriteHost = $True
  23. $inputfile = "$WorkingDirectory\Input\servers.txt"
  24. $logfolder = "$WorkingDirectory\Output\"
  25. $Trace32 = "$WorkingDirectory\Trace32"
  26. $timestamp = Get-Date -format "yyyy_MM_dd_HHmmss"
  27. $resultfile = $logfolder + "SCCM_Client_Reinstall_" + $Domain + "_" + $item + "_" + $timestamp + ".csv"
  28.  
  29. # Define services we will start and stop
  30. $bits = "bits"
  31. $wuauserv = "wuauserv"
  32. $appidsvc = "appidsvc"
  33. $cryptsvc = "cryptsvc"
  34. $ccmexec = "ccmexec"
  35.  
  36. # set PSexec path..
  37. Set-Alias psexec "$WorkingDirectory\psexec\psexec.exe"
  38.  
  39. # call out which domain we're running this script on based on environment variable.
  40. Write-Host "#------------------------------------------------------------#"
  41. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") "Running script in Domain: $Domain"
  42. Write-Host "#------------------------------------------------------------#"
  43.  
  44. # If log path doesn't exist create it..
  45. If (!(Test-Path -Path "$logfolder" -ErrorAction SilentlyContinue)) { New-Item "$logfolder" -Type Directory -ErrorAction SilentlyContinue | Out-Null }
  46.  
  47. # define 'functions' of the script
  48. Function Add_To_Log {
  49. Process {$_ | Add-Content -Path $resultfile}
  50. }
  51. Function Remove-CCMNamespace {
  52.             # If it exists:
  53.             if (get-wmiobject -query "Select * FROM __Namespace WHERE Name='ccm'" -Namespace "root" -Computername $computer)
  54.             {
  55.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Found ccm Namespace"
  56.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Deleting ccm Namespace"
  57.             # Delete
  58.             get-wmiobject -query "Select * FROM __Namespace WHERE Name='ccm'" -Namespace "root" -Computername $computer | Remove-WMIobject
  59.             Start-sleep -seconds 2
  60.             # Check Delete success/fail
  61.             $Status = Get-wmiobject -query "Select * FROM __Namespace WHERE Name='ccm'" -Namespace "root" -computername $Computer
  62.             if ($Status) {
  63.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red "Failed to delete ccm namespace WMI ISSUE"
  64.             Write-Output "$Computer, Failed to Delete CCM namespace, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  65.             } else {
  66.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully removed ccm namespace"}
  67.             }
  68.             Else {
  69.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "ccm namespace does not exist"
  70.                   }
  71. }
  72. Function Remove-SMSNamespace {
  73.             if (get-wmiobject -query "Select * FROM __Namespace WHERE Name='sms'" -Namespace "root\cimv2" -Computername $computer) {
  74.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Found SMS Namespace"
  75.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Deleting SMS Namespace"
  76.             get-wmiobject -query "Select * FROM __Namespace WHERE Name='sms'" -Namespace "root\cimv2" -Computername $computer | Remove-WMIobject
  77.             Start-sleep -seconds 2
  78.             $Status = Get-wmiobject -query "Select * FROM __Namespace WHERE Name='sms'" -Namespace "root\cimv2" -computername $Computer
  79.             if ($Status) {
  80.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "RED" "Failed to delete SMS namespace WMI ISSUES"
  81.             Write-Output "$Computer, Failed to Delete SMS namespace, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  82.             } else {
  83.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "Successfully removed SMS namespace"}
  84.             }
  85.             Else {
  86.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "SMS namespace does not exist"
  87.                   }
  88. }
  89. Function Verify-WMI {
  90. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Item "Running WMI Consistency Check winmgmt /verifyrepository"
  91. $computername = "\\$item"
  92. $Scriptblock = "winmgmt /verifyrepository"
  93.  
  94. ## Prepare the command line for PsExec. We use the XML output encoding so
  95. ## that PowerShell can convert the output back into structured objects.
  96. ## PowerShell expects that you pass it some input when being run by PsExec
  97. ## this way, so the 'echo .' statement satisfies that appetite.
  98. $commandLine = "echo . | powershell -Output XML "
  99.  
  100. ## Convert the command into an encoded command for PowerShell
  101. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  102. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  103. $commandLine += "-EncodedCommand $encodedCommand"
  104.  
  105. ## Collect the output and error output
  106. $errorOutput = [IO.Path]::GetTempFileName()
  107. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  108.  
  109. ## Check for any errors
  110. $errorContent = Get-Content $errorOutput
  111. Remove-Item $errorOutput
  112. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  113. {
  114.     $OFS = "`n"
  115.     $errorMessage = "Could not execute remote expression. "
  116.     $errorMessage += "Ensure that your account has administrative " +
  117.         "privileges on the target machine.`n"
  118.     $errorMessage += ($errorContent -match "psexec.exe :")
  119.  
  120.     Write-Error $errorMessage
  121. }
  122.  
  123. ## Return the output for use in if statement
  124. if ($output -eq "WMI repository is consistent")
  125.         {
  126.         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "green" $Item "WMI Check: Success"
  127.         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") $Output
  128.         Write-Output "$Item, WMI Consistency Check, success,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  129.         $SuccessfulResults += $Item
  130.         return $True
  131.         }
  132.         else
  133.         {
  134.         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Item "WMI Check: Failure"
  135.         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") $Output
  136.         Write-Output "$Item, WMI Consistency Check, Failed,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  137.         return $false
  138.         }
  139. }
  140. #Function Remove-WUSoftwareDistributionFolder {
  141. #$SoftwareDistributionPath = "\\$Computer\C$\Windows\SoftwareDistribution"
  142. #          
  143. #           Write-Output ("{0}, Removing Software Distribution folder and subfolders" -f $Computer) | Add_To_Log
  144. #            Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing Software Distribution folder and subfolders"
  145. #
  146. #                if (test-path -path "$SoftwareDistributionPath")
  147. #               {Try
  148. #                    {
  149. #                   $files = Get-ChildItem -file -literalpath $SoftwareDistributionPath -Recurse -force
  150. #                   $filecount = $files.count
  151. #                   $iteration = 0
  152. #                   Foreach ($file in $files) {
  153. #                       $iteration++
  154. #                       Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  155. #                       Remove-Item $file.fullname -recurse -force
  156. #                   }
  157. #                   Write-Progress -Completed -activity "Removing..."
  158. #                   Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  159. #                   Remove-item -literalPath $SoftwareDistributionPath -recurse -force
  160. #                  
  161. #                   Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $SoftwareDistributionPath exists"
  162. #                   Start-sleep -seconds 2
  163. #                  
  164. #                   if (test-path -literalpath $SoftwareDistributionPath) {
  165. #                   Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete $SoftwareDistributionPath"
  166. #                   } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $SoftwareDistributionPath"}
  167. #                   } Catch {
  168. #                       Write-Output ("{0}, {1} ERROR" -f $Computer,$_.Exception.Message) | Add_To_Log
  169. #                        Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  170. #                            }
  171. #               }
  172. #}
  173. function Rename-WUSoftwareDistributionFolder {
  174.                     $Path = "\\$Computer\C$\Windows\SoftwareDistribution"
  175.                     $NewName = "SoftwareDistribution" + "_" + $timestamp + ".old"
  176.                     $NewPath = "\\$Computer\C$\Windows\$NewName"
  177.                    
  178. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting to rename SoftwareDistribution Directory"
  179. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor white "from:"
  180. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "$Path"
  181. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor white "to:"
  182. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "$NewPath"
  183.                    
  184.                     Rename-item $Path -NewName $NewName
  185.                    
  186.                     Start-sleep -seconds 2
  187.                    
  188.                     if (test-path $NewPath) {
  189.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully renamed to: $NewName"
  190.                         # if new path exists... means we've likely successfully renamed directory
  191.                     }
  192.                     if (!(test-path $path)) {
  193.                             # AND original path no longer exists
  194.                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "$Path no longer exists"
  195.                             }                  
  196.                         # else since new path doesn't exist unlikely that original path has been renamed as it should...
  197.                         else {                 
  198.                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "$Path still exists!"
  199.                         }
  200. }
  201. Function Remove-Catroot2Folder {
  202. $catroot2Path = "\\$computer\C$\windows\syswow64\catroot2"
  203. $catroot2x86 = "\\$computer\C$\windows\system32\catroot2"
  204.            
  205. if (test-path -path $catroot2Path)
  206.                 {Try
  207.                     {
  208.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing $catroot2Path"
  209.                     $files = Get-ChildItem -file -literalpath $catroot2Path -Recurse -force
  210.                     $filecount = $files.count
  211.                     $iteration = 0
  212.                     Foreach ($file in $files) {
  213.                         $iteration++
  214.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  215.                         Remove-Item $file.fullname -recurse -force
  216.                     }
  217.                     Write-Progress -Completed -activity "Removing..."
  218.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  219.                     Remove-item -literalPath $catroot2Path -recurse -force
  220.                    
  221. # test to see if the delete actually worked
  222.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $catroot2Path exists"
  223.                     Start-sleep -seconds 2
  224.  
  225. if (test-path -literalpath $catroot2Path) {
  226.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete $catroot2Path"
  227.                     Write-Output ("$Computer, Failed to Delete $Catroot2Path, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss"),{0}" -f $_.ExceptionMessage) | Add_To_Log
  228.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $catroot2Path"}
  229.                     } Catch {
  230.                         Write-Output ("$Computer, Failed to Delete $Catroot2Path, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss"),{0}" -f $_.ExceptionMessage) | Add_To_Log
  231.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer $_.Exception.Message
  232.                             }
  233.                 }
  234.                
  235. # moving onto x86 path:
  236.                                
  237. if (test-path -path $catroot2x86)
  238.                 {Try
  239.                     {
  240.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing $catroot2x86"               
  241.                     $files = Get-ChildItem -file -literalpath $catroot2x86 -Recurse -force
  242.                     $filecount = $files.count
  243.                     $iteration = 0
  244.                     Foreach ($file in $files) {
  245.                         $iteration++
  246.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  247.                         Remove-Item $file.fullname -recurse -force
  248.                     }
  249.                     Write-Progress -Completed -activity "Removing..."
  250.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  251.                     Remove-item -literalPath $catroot2x86 -recurse -force
  252.                    
  253.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $catroot2x86 exists"
  254.                     Start-sleep -seconds 2
  255.                    
  256.                     if (test-path -literalpath $catroot2x86) {
  257.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete $catroot2x86"
  258.                     Write-Output "$Computer, Failed to Delete $catroot2x86, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  259.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $catroot2x86"}
  260.                     } Catch {
  261.                         Write-Output ("$Computer, Failed to Delete $catroot2x86, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss"),{0}" -f $_.ExceptionMessage) | Add_To_Log
  262.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  263.                             }
  264.                 }
  265. }
  266. Function Remove-CCMFolder {
  267. $ccmPath = "\\$computer\C$\windows\syswow64\ccm"
  268. $ccmPathx86 = "\\$computer\C$\windows\system32\ccm"
  269.            
  270. if (test-path -path $ccmPath)
  271.                 {Try
  272.                     {
  273.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing $ccmPath"
  274.                     $files = Get-ChildItem -file -literalpath $ccmPath -Recurse -force
  275.                     $filecount = $files.count
  276.                     $iteration = 0
  277.                     Foreach ($file in $files) {
  278.                         $iteration++
  279.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  280.                         Remove-Item $file.fullname -recurse -force
  281.                     }
  282.                     Write-Progress -Completed -activity "Removing..."
  283.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  284.                     Remove-item -literalPath $ccmPath -recurse -force
  285.                    
  286. # test to see if the delete actually worked
  287.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $ccmPath exists"
  288.                     Start-sleep -seconds 2
  289.  
  290. if (test-path -literalpath $ccmPath) {
  291.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete $ccmPath"
  292.                     Write-Output "$Computer, Failed to Delete $ccmPath, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  293.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $ccmPath"}
  294.                     } Catch {
  295.                     Write-Output "$Computer, Failed to Delete $ccmpath, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  296.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  297.                             }
  298.                 }
  299.                
  300. # moving onto x86 path:
  301.                                
  302. if (test-path -path $ccmPathx86)
  303.                 {Try
  304.                     {
  305.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing $ccmPathx86"            
  306.                     $files = Get-ChildItem -file -literalpath $ccmPathx86 -Recurse -force
  307.                     $filecount = $files.count
  308.                     $iteration = 0
  309.                     Foreach ($file in $files) {
  310.                         $iteration++
  311.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  312.                         Remove-Item $file.fullname -recurse -force
  313.                     }
  314.                     Write-Progress -Completed -activity "Removing..."
  315.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  316.                     Remove-item -literalPath $ccmPathx86 -recurse -force
  317.                    
  318.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $ccmPathx86 exists"
  319.                     Start-sleep -seconds 2
  320.                    
  321.                     if (test-path -literalpath $ccmPathx86) {
  322.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete $ccmPathx86"
  323.                     Write-Output "$Computer, Failed to Delete $ccmPathx86, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  324.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $ccmPathx86"}
  325.                     } Catch {
  326.                         Write-Output "$Computer, Failed to Delete $ccmPathx86, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  327.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  328.                             }
  329.                 }
  330. }
  331. Function Remove-CCMCacheFolder {
  332. $ccmcachePath = "\\$Computer\C$\windows\syswow64\ccm\cache"
  333. $ccmcachePathx86 = "\\$Computer\c$\Windows\system32\ccm\cache"
  334.            
  335. if (test-path -path $ccmcachePath)
  336.                 {Try
  337.                     {
  338.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing $ccmcachePath"
  339.                     $files = Get-ChildItem -file -literalpath $ccmcachePath -Recurse -force
  340.                     $filecount = $files.count
  341.                     $iteration = 0
  342.                     Foreach ($file in $files) {
  343.                         $iteration++
  344.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  345.                         Remove-Item $file.fullname -recurse -force
  346.                     }
  347.                     Write-Progress -Completed -activity "Removing..."
  348.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  349.                     Remove-item -literalPath $ccmcachePath -recurse -force
  350.                    
  351. # test to see if the delete actually worked
  352.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $ccmcachePath exists"
  353.                     Start-sleep -seconds 2
  354.  
  355. if (test-path -literalpath $ccmcachePath) {
  356.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete $ccmcachePath"
  357.                     Write-Output "$Computer, Failed to Delete $ccmcachepath, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  358.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $ccmcachePath"}
  359.                     } Catch {
  360.                         Write-Output "$Computer, Failed to Delete $ccmcachepath, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  361.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  362.                             }
  363.                 }
  364.                
  365. # moving onto x86 path:
  366.                                
  367. if (test-path -path $ccmcachePathx86)
  368.                 {Try
  369.                     {
  370.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing $ccmcachePathx86"               
  371.                     $files = Get-ChildItem -file -literalpath $ccmcachePathx86 -Recurse -force
  372.                     $filecount = $files.count
  373.                     $iteration = 0
  374.                     Foreach ($file in $files) {
  375.                         $iteration++
  376.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  377.                         Remove-Item $file.fullname -recurse -force
  378.                     }
  379.                     Write-Progress -Completed -activity "Removing..."                  
  380.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  381.                     Remove-item -literalPath $ccmcachePathx86 -recurse -force
  382.                    
  383.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $ccmcachePathx86 exists"
  384.                     Start-sleep -seconds 2
  385.                    
  386.                     if (test-path -literalpath $ccmcachePathx86) {
  387.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete $ccmcachePathx86"
  388.                     Write-Output "$Computer, Failed to Delete $ccmcachepathx86, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  389.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $ccmcachePathx86"}
  390.                     } Catch {
  391.                         Write-Output "$Computer, Failed to Delete $ccmcachepathx86, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  392.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  393.                             }
  394.                 }
  395. }
  396. Function Remove-CCMSetupFolder {
  397. $ccmsetupPath = "\\$Computer\C$\windows\ccmsetup"
  398. $ccmsetupPathx86 = "\\$computer\C$\windows\system32\ccmsetup"
  399.            
  400. if (test-path -path $ccmsetupPath)
  401.                 {Try
  402.                     {
  403.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing $ccmsetupPath"
  404.                     $files = Get-ChildItem -file -literalpath $ccmsetupPath -Recurse -force
  405.                     $filecount = $files.count
  406.                     $iteration = 0
  407.                     Foreach ($file in $files) {
  408.                         $iteration++
  409.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  410.                         Remove-Item $file.fullname -recurse -force
  411.                     }
  412.                     Write-Progress -Completed -activity "Removing..."
  413.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  414.                     Remove-item -literalPath $ccmsetupPath -recurse -force
  415.                    
  416. # test to see if the delete actually worked
  417.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $ccmsetupPath exists"
  418.                     Start-sleep -seconds 2
  419.  
  420. if (test-path -literalpath $ccmsetupPath) {
  421.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete $ccmsetupPath"
  422.                     Write-Output "$Computer, Failed to Delete $ccmsetupPath, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  423.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $ccmsetupPath"}
  424.                     } Catch {
  425.                         Write-Output "$Computer, Failed to Delete $ccmsetupPath, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  426.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  427.                             }
  428.                 }
  429.                
  430. # moving onto x86 path:
  431.                                
  432. if (test-path -path $ccmsetupPathx86)
  433.                 {Try
  434.                     {
  435.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing $ccmsetupPathx86"               
  436.                     $files = Get-ChildItem -file -literalpath $ccmsetupPathx86 -Recurse -force
  437.                     $filecount = $files.count
  438.                     $iteration = 0
  439.                     Foreach ($file in $files) {
  440.                         $iteration++
  441.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  442.                         Remove-Item $file.fullname -recurse -force
  443.                     }
  444.                     Write-Progress -Completed -activity "Removing..."
  445.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "Done with foreach, moving to delete the whole directory and empty folder structure"
  446.                     Remove-item -literalPath $ccmsetupPathx86 -recurse -force
  447.                    
  448.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $ccmsetupPathx86 exists"
  449.                     Start-sleep -seconds 2
  450.                    
  451.                     if (test-path -literalpath $ccmsetupPathx86) {
  452.                     Write-Output "$Computer, Found $ccmsetupPathx86, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  453.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted $ccmsetupPathx86"}
  454.                     } Catch {
  455.                         Write-Output "$Computer, Found $ccmsetupPathx86, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  456.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  457.                             }
  458.                 }
  459. }
  460. Function Remove-qmgrdatfiles {
  461. $qmgrdatxpPath = "\\$Computer\c$\Documents and Settings\All Users\Application Data\Microsoft\Network\Downloader"
  462. $qmgrdatwin7Path = "\\$Computer\C$\ProgramData\Microsoft\Network\Downloader"
  463.            
  464. if (test-path -path $qmgrdatwin7Path)
  465.                 {Try
  466.                     {
  467.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing qmgr*.dat files in $qmgrdatwin7Path"
  468.                     $files = Get-ChildItem -file -literalpath $qmgrdatwin7Path -Recurse -force | where {$_.Name -like "qmgr*.dat"}
  469.                     $filecount = $files.count
  470.                     $iteration = 0
  471.                     Foreach ($file in $files) {
  472.                         $iteration++
  473.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  474.                         Remove-Item $file.fullname -recurse -force
  475.                     }
  476.                     Write-Progress -Completed -activity "Removing..."
  477.                    
  478. # test to see if the delete actually worked
  479.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $files exist in $qmgrdatwin7Path"
  480.                     Start-sleep -seconds 2
  481. # if files exist then delete failed
  482. if (Get-Childitem -literalpath $qmgrdatwin7Path -file | where {$_.Name -like "qmgr*.dat"}) {
  483.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete qmgr*.dat files"
  484.                     Write-Output "$Computer, Failed to Delete qmgr*.dat files, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  485.                     }
  486. # if files don't exist in that location delete was successful.
  487.                     else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted qmgr*.dat files"}
  488.                     }
  489. #catch any errors in this process                  
  490.                     Catch {
  491.                         Write-Output "$Computer, Failed to Delete $qmgrdatwin7Path, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  492.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  493.                             }
  494.                 }
  495. # moving onto XP path:
  496. if (test-path -path $qmgrdatxpPath)
  497.                 {Try
  498.                     {
  499.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Removing qmgr*.dat files in $qmgrdatxpPath"
  500.                     $files = Get-ChildItem -file -literalpath $qmgrdatxpPath -Recurse -force | where {$_.Name -like "qmgr*.dat"}
  501.                     $filecount = $files.count
  502.                     $iteration = 0
  503.                     Foreach ($file in $files) {
  504.                         $iteration++
  505.                         Write-Progress -activity "Removing..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  506.                         Remove-Item $file.fullname -recurse -force
  507.                     }
  508.                     Write-Progress -Completed -activity "Removing..."
  509.                    
  510. # test to see if the delete actually worked
  511.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "checking to see if $files exist in $qmgrdatxpPath"
  512.                     Start-sleep -seconds 2
  513.  
  514. if (Get-Childitem -literalpath $qmgrdatxpPath -file | where {$_.Name -like "qmgr*.dat"}) {
  515.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer "Failed to Delete qmgr*.dat files"
  516.                     Write-Output "$Computer, Failed to Delete qmgr*.dat files, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  517.                     } else {Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Deleted qmgr*.dat files"}
  518.                     } Catch {
  519.                         Write-Output "$Computer, Failed to Delete qmgr*.dat files, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  520.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" ($Computer,$_.Exception.Message)
  521.                             }
  522.                 }
  523. }
  524. Function Force-WUAgentDetectnow {
  525.  
  526. $computername = "\\$computer"
  527. $Scriptblock = "wuauclt /resetauthorization /detectnow"
  528.  
  529. ## Prepare the command line for PsExec. We use the XML output encoding so
  530. ## that PowerShell can convert the output back into structured objects.
  531. ## PowerShell expects that you pass it some input when being run by PsExec
  532. ## this way, so the 'echo .' statement satisfies that appetite.
  533. $commandLine = "echo . | powershell -Output XML "
  534.  
  535. ## Convert the command into an encoded command for PowerShell
  536. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  537. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  538. $commandLine += "-EncodedCommand $encodedCommand"
  539.  
  540. ## Collect the output and error output
  541. $errorOutput = [IO.Path]::GetTempFileName()
  542. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  543.  
  544. ## Check for any errors
  545. $errorContent = Get-Content $errorOutput
  546. Remove-Item $errorOutput
  547. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  548. {
  549.     $OFS = "`n"
  550.     $errorMessage = "Could not execute remote expression. "
  551.     $errorMessage += "Ensure that your account has administrative " +
  552.         "privileges on the target machine.`n"
  553.     $errorMessage += ($errorContent -match "psexec.exe :")
  554.  
  555.     Write-Error $errorMessage
  556. }
  557.  
  558. ## run the scriptblock:
  559.  
  560. if ($output -eq $null) {
  561. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "green" $computer "Successfully sent wuauclt /detectnow /resetauthorization"
  562. } else {
  563. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Something went wrong sending wuauclt /detectnow /resetauthorization"
  564. Write-Output "$Computer, Something went wrong wuauclt detectnow not sent or received properly.. not so much an issue.. WUAgent should recover by itself in time, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  565. }
  566. }
  567. Function Copy-SCCMClientInstallation {
  568. $destinationparentdir = "\\$Computer\C$\temp"
  569. $sourcePath = "$WorkingDirectory\Client"
  570. $destinationPath = "\\$Computer\C$\Temp\SCCMClientInstall\Client"
  571.  
  572. # if c:\temp on target machine doesn't exist, create it
  573. if (!(Test-path $destinationparentdir)) {
  574.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") "Creating Directory" -foregroundcolor "green" $destinationparentdir
  575.                 New-Item "$destinationparentdir" -Type Directory -ErrorAction SilentlyContinue | Out-Null }
  576.  
  577. # if we haven't already copied files to target machine do so.
  578. if (!(Test-path $destinationPath)) {
  579. $files = Get-ChildItem -Path $sourcePath -Recurse
  580. $filecount = $files.count
  581. $iteration = 0
  582.  
  583. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -Foregroundcolor "Yellow" $Computer "Copying from $SourcePath to $DestinationPath"
  584.  
  585. Foreach ($file in $files) {
  586.     $iteration++
  587.     Write-Progress -activity "Copying..." -status "$file ($iteration of $filecount)" -percentcomplete (($iteration/$filecount)*100)
  588.  
  589.     # Determine the absolute path of this object's parent container.  This is stored as a different attribute on file and folder objects so we use an if block to cater for both
  590.     if ($file.psiscontainer) {$sourcefilecontainer = $file.parent} else {$sourcefilecontainer = $file.directory}
  591.  
  592.     # Calculate the path of the parent folder relative to the source folder
  593.     $relativepath = $sourcefilecontainer.fullname.SubString($sourcepath.length)
  594.  
  595.     # Copy the object to the appropriate folder within the destination folder
  596.     Copy-Item $file.fullname ($destinationPath + $relativepath)
  597. }
  598. Write-Progress -Completed -activity "Copying..."
  599. }
  600.     else {
  601.     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -Foregroundcolor "yellow" $Computer "SCCM Client installation files already exist on this machine, suggests script has run before"
  602.     }
  603. }
  604. Function LoadCCMsetupLog {
  605. if (test-path -path \\$Computer\C$\windows\ccmsetup) {Start $Trace32\Trace32.exe \\$Computer\C$\Windows\ccmsetup\ccmsetup.log}
  606.                 elseif (test-path -path \\$Computer\C$\windows\system32\ccmsetup) {Start $Trace32\Trace32.exe \\$Computer\C$\windows\system32\ccmsetup\ccmsetup.log}
  607.                 elseif (test-path -path \\$Computer\C$\winnt) {Start $Trace32\Trace32.exe \\$Computer\C$\winnt\system32\ccmsetup\ccmsetup.log}
  608. }
  609. Function Uninstall-SCCMClient {
  610. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Yellow" $Computer "Running SCCM Client Uninstall"
  611. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "green" $Computer Opening Log
  612. LoadCCMSetupLog
  613.                 if (test-path -path "\\$Computer\C$\windows\syswow64") {
  614.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "green" $Computer "Detected x64 running SCCM Uninstall"
  615.                
  616.                 psexec \\$computer C:\temp\SCCMClientInstall\Client\ccmsetup.exe /uninstall
  617.                 }
  618.                 elseif (test-path -path "\\$Computer\C$\windows\system32") {
  619.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "green" $computer "Detected x86 running SCCM Uninstall"
  620.                
  621.                 psexec \\$computer C:\temp\SCCMClientInstall\Client\ccmsetup.exe /uninstall
  622.                 }
  623.                
  624.                 Start-sleep -seconds 7
  625.                 Get-process Trace32 | stop-process     
  626. }
  627. Function Install-SCCMClient {
  628.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Beginning SCCM Client Reinstall"
  629.                
  630. psexec \\$computer C:\temp\SCCMClientInstall\Client\ccmsetup.exe /mp:melysccm1.oceania.cshare.net SMSSITECODE=O01 SMSSLP=melysccm1.oceania.cshare.net CCMLOGLEVEL=0 CCMLOGMAXHISTORY=3 RESETKEYINFORMATION=TRUE FSP=melysccm1.oceania.cshare.net
  631.  
  632.                 Start-sleep -seconds 2
  633.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "green" $Computer Opening Log
  634.                 LoadCCMSetupLog
  635.                 CheckifCCMSetupStillRunning    
  636. }
  637. Function CheckifCCMsetupStillrunning {
  638. Start-sleep -seconds 1
  639. if (Get-process -ComputerName $Computer ccmsetup) {
  640.                 do {
  641.                 $Process = Get-Process -ComputerName $Computer | where {$_.ProcessName -eq "ccmsetup"}
  642.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow "ccmsetup.exe still running on $Computer - please be patient"
  643.                 Start-Sleep -Seconds 5
  644.                 } until ($Process -eq $null)
  645.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") ("{0}: CCMsetup.exe has exited" -f $Computer)
  646.                 }
  647. }
  648. Function Confirm-BitsExists {
  649.                 if (Get-Service -Name $bits -Computername $Computer -ErrorAction SilentlyContinue)
  650.                 {
  651.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "$bits Exists"
  652.                     return $true
  653.                 }
  654.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "$bits does NOT exist on this computer"
  655.                 Write-Output "$Computer, $bits service does NOT exist, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  656.                     return $false
  657. }
  658. Function Confirm-WuauservExists {  
  659.                 if (Get-Service -Name $wuauserv -Computername $Computer -ErrorAction SilentlyContinue)
  660.                 {
  661.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "$wuauserv Exists"
  662.                     return $true
  663.                 }
  664.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "$wuauserv does NOT exist on this computer"
  665.                     Write-Output "$Computer, $wuauserv service does not exist, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  666.                     return $false
  667. }
  668. Function Confirm-AppIDsvcExists {
  669.                 if (Get-Service -Name $appidsvc -Computername $Computer -ErrorAction SilentlyContinue)
  670.                 {
  671.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "$appidsvc Exists"
  672.                     return $true
  673.                 }
  674.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "$appidsvc does NOT exist on this computer"
  675.                     Write-Output "$Computer, $appidsvc does NOT exist, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  676.                     return $false
  677. }
  678. Function Confirm-cryptsvcExists {
  679.                 if (Get-Service -Name $cryptsvc -Computername $Computer -ErrorAction SilentlyContinue)
  680.                 {
  681.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "$cryptsvc Exists"
  682.                     return $true
  683.                 }
  684.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "$cryptsvc does NOT exist on this computer"
  685.                     Write-Output "$Computer, $cryptsvc does NOT exist, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  686.                     return $false
  687. }
  688. Function Confirm-ccmexecExists {
  689.                 if (Get-Service -Name $ccmexec -Computername $Computer -ErrorAction SilentlyContinue)
  690.                 {
  691.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "$ccmexec Exists"
  692.                     return $true
  693.                 }
  694.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "$ccmexec does NOT exist on this computer"
  695.                     Write-Output "$Computer, $ccmexec service does NOT exist, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  696.                     return $false
  697. }
  698. Function Stop-BitsIfItExists {
  699.                 $bitsexists = Confirm-BitsExists $bitsexists
  700.                 if ($bitsexists) {
  701.                                         $bitsstatus = Get-Service -computername $Computer -name $bits
  702.                                         if ($bitsstatus |  Where {$_.Status -eq "Running"})
  703.                                             {
  704.                                             #get-service -computername $computer $bits | set-service -startuptype Disabled
  705.                                             SC.exe ("\\" + $Computer) CONFIG $bits start= disabled
  706.                                             Start-sleep -seconds 2
  707.                                             SC.exe ("\\" + $Computer) Stop $bits
  708.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Stopping $bits service"
  709.                                             start-sleep 20
  710.                                             $bitsstatus2 = Get-Service -computername $Computer -name $bits
  711.                                                 if ($bitsstatus2 |  Where {$_.Status -eq "Stopped"} ) {
  712.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "Service successfully stopped...$bits"
  713.                                                 } else {
  714.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Failed to stop...$bits"
  715.                                                 Write-Output "$Computer, $bits Failed to Stop, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  716.                                                 }
  717.                                             }
  718.                                             elseif ($bitsstatus |  Where {$_.Status -eq "Stopped"}) {
  719.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "$bits already stopped"
  720.                                             }
  721.                                     }
  722. }
  723. Function Stop-WuauservIfItExists {
  724.                 $wuauservexists = Confirm-WuauservExists $wuauservexists
  725.                 if ($wuauservexists) {
  726.                                         $wuauservstatus = Get-Service -computername $Computer -name $wuauserv
  727.                                         if ($wuauservstatus |  Where {$_.Status -eq "Running"})
  728.                                             {
  729.                                             #get-service -computername $computer $wuauserv | set-service -startuptype Disabled
  730.                                             SC.exe ("\\" + $Computer) CONFIG $wuauserv start= disabled
  731.                                             Start-sleep -seconds 2
  732.                                             SC.exe ("\\" + $Computer) Stop $wuauserv
  733.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Stopping $wuauserv service"
  734.                                             start-sleep 20
  735.                                             $wuauservstatus2 = Get-Service -computername $Computer -name $wuauserv
  736.                                             if ($wuauservstatus2 |  Where {$_.Status -eq "Stopped"} ) {
  737.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "Service successfully stopped...$wuauserv"
  738.                                                 } else {
  739.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Failed to stop...$wuauserv"
  740.                                                 Write-Output "$Computer, $wuauserv Failed to Stop, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  741.                                                 }
  742.                                             }
  743.                                             elseif ($wuauservstatus |  Where {$_.Status -eq "Stopped"}) {
  744.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "$wuauserv already stopped"
  745.                                             }
  746.                                     }
  747. }
  748. Function Stop-appidsvcIfItExists {
  749.                 $appidsvcexists = Confirm-appidsvcExists $appidsvcexists
  750.                 if ($appidsvcexists) {
  751.                                         $appidsvcstatus = Get-Service -computername $Computer -name $appidsvc
  752.                                         if ($appidsvcstatus |  Where {$_.Status -eq "Running"})
  753.                                             {
  754.                                             #get-service -computername $computer $appidsvc | set-service -startuptype Disabled
  755.                                             SC.exe ("\\" + $Computer) CONFIG $appidsvc start= disabled
  756.                                             Start-sleep -seconds 2
  757.                                             SC.exe ("\\" + $Computer) Stop $appidsvc
  758.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Stopping $appidsvc service"
  759.                                             start-sleep 20
  760.                                             $appidsvcstatus2 = Get-Service -computername $Computer -name $appidsvc
  761.                                                 if ($appidsvcstatus2 |  Where {$_.Status -eq "Stopped"} ) {
  762.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "Service successfully stopped...$appidsvc"
  763.                                                 } else {
  764.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Failed to stop...$appidsvc"
  765.                                                 Write-Output ("{0}, $appidsvc Failed to stop" -f $Computer) | Add_To_Log
  766.                                                 Write-Output "$Computer, $appidsvc Failed to Stop, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  767.                                                 }
  768.                                             }
  769.                                             elseif ($appidsvcstatus |  Where {$_.Status -eq "Stopped"}) {
  770.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "$appidsvc already stopped"
  771.                                             }
  772.                                     }
  773. }
  774. Function Stop-cryptsvcIfItExists {
  775.                 $cryptsvcexists = Confirm-cryptsvcExists $cryptsvcexists
  776.                 if ($cryptsvcexists) {
  777.                                         $cryptsvcstatus = Get-Service -computername $Computer -name $cryptsvc
  778.                                         if ($cryptsvcstatus |  Where {$_.Status -eq "Running"})
  779.                                             {
  780.                                             #get-service -computername $computer $cryptsvc | set-service -startuptype Disabled
  781.                                             SC.exe ("\\" + $Computer) CONFIG $cryptsvc start= disabled
  782.                                             Start-sleep -seconds 2
  783.                                             SC.exe ("\\" + $Computer) Stop $cryptsvc
  784.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Stopping $cryptsvc service"
  785.                                             start-sleep 20
  786.                                             $cryptsvcstatus2 = Get-Service -computername $Computer -name $cryptsvc
  787.                                             if ($cryptsvcstatus2 |  Where {$_.Status -eq "Stopped"} ) {
  788.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "Service successfully stopped...$cryptsvc"
  789.                                                 } else {
  790.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Failed to stop...$cryptsvc"
  791.                                                 Write-Output "$Computer, $cryptsvc Failed to Stop, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  792.                                                 }
  793.                                             }
  794.                                             elseif ($cryptsvcstatus |  Where {$_.Status -eq "Stopped"}) {
  795.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "$cryptsvc already stopped"
  796.                                             }
  797.                                     }
  798. }
  799. Function Stop-ccmexecIfItExists {
  800.                 $ccmexecexists = Confirm-ccmexecExists $ccmexecexists
  801.                 if ($ccmexecexists) {
  802.                                         $ccmexecstatus = Get-Service -computername $Computer -name $ccmexec
  803.                                         if ($ccmexecstatus |  Where {$_.Status -eq "Running"})
  804.                                             {
  805.                                             #get-service -computername $computer $ccmexec | set-service -startuptype Disabled
  806.                                             SC.exe ("\\" + $Computer) Stop $ccmexec
  807.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Stopping $ccmexec service"
  808.                                             start-sleep 20
  809.                                             $ccmexecstatus2 = Get-Service -computername $Computer -name $ccmexec
  810.                                             if ($ccmexecstatus2 |  Where {$_.Status -eq "Stopped"} ) {
  811.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "Service successfully stopped...$ccmexec"
  812.                                                 } else {
  813.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Failed to stop...$ccmexec"
  814.                                                 Write-Output "$Computer, $ccmexec Failed to stop, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  815.                                                 }
  816.                                             }
  817.                                             elseif ($ccmexecstatus |  Where {$_.Status -eq "Stopped"}) {
  818.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "$ccmexec already stopped"
  819.                                             }
  820.                                     }
  821. }
  822. Function Stop-iphlpsvcIfItExists {
  823.                 $iphlpsvcexists = Confirm-iphlpsvcExists $iphlpsvcexists
  824.                 if ($iphlpsvcexists) {
  825.                                         $iphlpsvcstatus = Get-Service -computername $Computer -name $iphlpsvc
  826.                                         if ($iphlpsvcstatus |  Where {$_.Status -eq "Running"})
  827.                                             {
  828.                                             #get-service -computername $computer $iphlpsvc | set-service -startuptype Disabled
  829.                                             SC.exe ("\\" + $Computer) CONFIG $iphlpsvc start= disabled
  830.                                             Start-sleep -seconds 2
  831.                                             SC.exe ("\\" + $Computer) Stop $iphlpsvc
  832.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Stopping $iphlpsvc service"
  833.                                             start-sleep 20
  834.                                             $iphlpsvcstatus2 = Get-Service -computername $Computer -name $iphlpsvc
  835.                                             if ($iphlpsvcstatus2 |  Where {$_.Status -eq "Stopped"} ) {
  836.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer "Service successfully stopped...$iphlpsvc"
  837.                                                 } else {
  838.                                                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "Failed to stop...$iphlpsvc"
  839.                                                 Write-Output "$Computer, $iphlpsvc Failed to stop, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  840.                                                 }
  841.                                             }
  842.                                             elseif ($iphlpsvcstatus |  Where {$_.Status -eq "Stopped"}) {
  843.                                             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "$iphlpsvc already stopped"
  844.                                             }
  845.                                     }
  846. }
  847. Function Start-WuauservIfItExists {
  848. $wuauservexists = Confirm-wuauservExists $wuauservexists
  849. if ($wuauservexists) {
  850.                 #get-service -computername $computer $Wuauserv | set-service -startuptype automatic
  851.                 SC.exe ("\\" + $Computer) CONFIG $wuauserv start= auto
  852.                 Start-Sleep -seconds 2
  853.                 SC.exe ("\\" + $Computer) Start $Wuauserv
  854.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer ("Service Starting..." + $Wuauserv)
  855.                 Start-Sleep -Seconds 20
  856.                 $status = Get-Service -computername $Computer $Wuauserv | where {$_.Status -eq "Running"}
  857.                 if (($status).status -eq "Running")
  858.                 {
  859.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer ("Service Started Successfully..." + $Wuauserv)
  860.                 }
  861.                 else {
  862.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Red" $Computer ("Service failed to start..." + $Wuauserv)
  863.                 Write-Output "$Computer, $Wuauserv Failed to start, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  864.                 }
  865.                 }
  866. }
  867. Function Start-AppIDsvcIfItExists {
  868. $AppIDsvcexists = Confirm-AppIDsvcExists $AppIDsvcexists
  869. if ($AppIDsvcexists) {
  870.                 #get-service -computername $computer $AppIDsvc | set-service -startuptype automatic
  871.                 SC.exe ("\\" + $Computer) CONFIG $appidsvc start= auto
  872.                 Start-Sleep -seconds 2
  873.                 SC.exe ("\\" + $Computer) Start $AppIDsvc
  874.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer ("Service Starting..." + $AppIDsvc)
  875.                 Start-Sleep -Seconds 20
  876.                 $status = Get-Service -computername $Computer $AppIDsvc | where {$_.Status -eq "Running"}
  877.                 if (($status).status -eq "Running")
  878.                 {
  879.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer ("Service Started Successfully..." + $AppIDsvc)
  880.                 }
  881.                 else {
  882.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Red" $Computer ("Service failed to start..." + $AppIDsvc)
  883.                 Write-Output "$Computer, $AppIDsvc failed to start, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  884.                 }
  885.                 }
  886. }
  887. Function Start-iphlpsvcIfItExists {
  888. $iphlpsvcexists = Confirm-iphlpsvcexists $iphlpsvcexists
  889. if ($iphlpsvcexists) {
  890.                 #get-service -computername $computer $iphlpsvc | set-service -startuptype automatic
  891.                 SC.exe ("\\" + $Computer) CONFIG $iphlpsvc start= auto
  892.                 Start-Sleep -seconds 2
  893.                 SC.exe ("\\" + $Computer) Start $iphlpsvc
  894.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer ("Service Starting..." + $iphlpsvc)
  895.                 Start-Sleep -Seconds 20
  896.                 $status = Get-Service -computername $Computer $iphlpsvc | where {$_.Status -eq "Running"}
  897.                 if (($status).status -eq "Running")
  898.                 {
  899.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer ("Service Started Successfully..." + $iphlpsvc)
  900.                 }
  901.                 else {
  902.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Red" $Computer ("Service failed to start..." + $iphlpsvc)
  903.                 Write-Output "$Computer, $iphlpsvc failed to start, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  904.                 }
  905.                 }
  906. }
  907. Function Start-CryptSvcIfItExists {
  908. $CryptSvcexists = Confirm-CryptSvcexists $CryptSvcexists
  909. if ($CryptSvcexists) {
  910.                 #get-service -computername $computer $cryptsvc | set-service -startuptype automatic
  911.                 SC.exe ("\\" + $Computer) CONFIG $cryptsvc start= auto
  912.                 Start-Sleep -seconds 2
  913.                 SC.exe ("\\" + $Computer) Start $cryptsvc
  914.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer ("Service Starting..." + $cryptsvc)
  915.                 Start-Sleep -Seconds 20
  916.                 $status = Get-Service -computername $Computer $cryptsvc | where {$_.Status -eq "Running"}
  917.                 if (($status).status -eq "Running")
  918.                 {
  919.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" $Computer ("Service Started Successfully..." + $cryptsvc)
  920.                 }
  921.                 else {
  922.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Red" $Computer ("Service failed to start..." + $cryptsvc)
  923.                 Write-Output "$Computer, $cryptsvc failed to start, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  924.                 }
  925.                 }
  926. }
  927. Function Start-bitsIfItExists {
  928. $bitsexists = Confirm-bitsexists $bitsexists
  929. if ($bitsexists) {
  930.                 #get-service -computername $computer $bits | set-service -startuptype Manual
  931.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Setting $bits to manual startup"
  932.                 SC.exe ("\\" + $Computer) CONFIG $bits start= demand
  933.                 Start-sleep -seconds 2
  934.                 ##MISSING A CHECK TO FIND OUT IF SERVICE WAS SUCCESSFULLY SET TO MANUAL HERE#####################################################################################
  935.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "green" $Computer "Set $bits service to Manual startup ..it does not need to be started"
  936. }
  937. }
  938. Function Reset-security-descriptor-bits {
  939. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting to reset security descriptor on $bits service"
  940. $Setbitsdescriptor = SC.exe ("\\" + $Computer) sdset bits "D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)"
  941. If ($Setbitsdescriptor -eq "[SC] SetServiceObjectSecurity SUCCESS") {
  942. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Reset Security Descriptor on $bits service"
  943. }
  944. else {
  945. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer"Failed to reset security descriptor on $bits service"
  946. }
  947. }
  948. Function Reset-security-descriptor-wuauserv {
  949. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting to reset security descriptor on $wuauserv service"
  950.  
  951. $Setwuauservdescriptor = SC.exe ("\\" + $Computer) sdset wuauserv "D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)"
  952. If ($Setwuauservdescriptor -eq "[SC] SetServiceObjectSecurity SUCCESS") {
  953. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer "Successfully Reset Security Descriptor on $wuauserv service"
  954. }
  955. else {
  956. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red $Computer"Failed to reset security descriptor on $wuauserv service"
  957. }
  958. }
  959. Function reset-Bitsadmin {
  960.  
  961. $computername = "\\$computer"
  962. $Scriptblock = "bitsadmin.exe /reset /allusers"
  963.  
  964. ## Prepare the command line for PsExec. We use the XML output encoding so
  965. ## that PowerShell can convert the output back into structured objects.
  966. ## PowerShell expects that you pass it some input when being run by PsExec
  967. ## this way, so the 'echo .' statement satisfies that appetite.
  968. $commandLine = "echo . | powershell -Output XML "
  969.  
  970. ## Convert the command into an encoded command for PowerShell
  971. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  972. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  973. $commandLine += "-EncodedCommand $encodedCommand"
  974.  
  975. ## Collect the output and error output
  976. $errorOutput = [IO.Path]::GetTempFileName()
  977. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  978.  
  979. ## Check for any errors
  980. $errorContent = Get-Content $errorOutput
  981. Remove-Item $errorOutput
  982. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  983. {
  984.     $OFS = "`n"
  985.     $errorMessage = "Could not execute remote expression. "
  986.     $errorMessage += "Ensure that your account has administrative " +
  987.         "privileges on the target machine.`n"
  988.     $errorMessage += ($errorContent -match "psexec.exe :")
  989.  
  990.     Write-Error $errorMessage
  991. }
  992.  
  993. ## Return the output for use in if statement
  994.  
  995. $output
  996. }
  997. Function registerWU-atl-dll {
  998.  
  999. $computername = "\\$computer"
  1000. $Scriptblock = "regsvr32.exe /s atl.dll"
  1001.  
  1002. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1003.  
  1004. ## Prepare the command line for PsExec. We use the XML output encoding so
  1005. ## that PowerShell can convert the output back into structured objects.
  1006. ## PowerShell expects that you pass it some input when being run by PsExec
  1007. ## this way, so the 'echo .' statement satisfies that appetite.
  1008. $commandLine = "echo . | powershell -Output XML "
  1009.  
  1010. ## Convert the command into an encoded command for PowerShell
  1011. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1012. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1013. $commandLine += "-EncodedCommand $encodedCommand"
  1014.  
  1015. ## Collect the output and error output
  1016. $errorOutput = [IO.Path]::GetTempFileName()
  1017. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1018.  
  1019. ## Check for any errors
  1020. $errorContent = Get-Content $errorOutput
  1021. Remove-Item $errorOutput
  1022. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1023. {
  1024.     $OFS = "`n"
  1025.     $errorMessage = "Could not execute remote expression. "
  1026.     $errorMessage += "Ensure that your account has administrative " +
  1027.         "privileges on the target machine.`n"
  1028.     $errorMessage += ($errorContent -match "psexec.exe :")
  1029.  
  1030.     Write-Error $errorMessage
  1031. }
  1032.  
  1033. ## Return the output for use in if statement
  1034.  
  1035. $output
  1036. }
  1037. Function registerWU-urlmon-dll {
  1038.  
  1039. $computername = "\\$computer"
  1040. $Scriptblock = "regsvr32.exe /s urlmon.dll"
  1041.  
  1042. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1043.  
  1044. ## Prepare the command line for PsExec. We use the XML output encoding so
  1045. ## that PowerShell can convert the output back into structured objects.
  1046. ## PowerShell expects that you pass it some input when being run by PsExec
  1047. ## this way, so the 'echo .' statement satisfies that appetite.
  1048. $commandLine = "echo . | powershell -Output XML "
  1049.  
  1050. ## Convert the command into an encoded command for PowerShell
  1051. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1052. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1053. $commandLine += "-EncodedCommand $encodedCommand"
  1054.  
  1055. ## Collect the output and error output
  1056. $errorOutput = [IO.Path]::GetTempFileName()
  1057. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1058.  
  1059. ## Check for any errors
  1060. $errorContent = Get-Content $errorOutput
  1061. Remove-Item $errorOutput
  1062. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1063. {
  1064.     $OFS = "`n"
  1065.     $errorMessage = "Could not execute remote expression. "
  1066.     $errorMessage += "Ensure that your account has administrative " +
  1067.         "privileges on the target machine.`n"
  1068.     $errorMessage += ($errorContent -match "psexec.exe :")
  1069.  
  1070.     Write-Error $errorMessage
  1071. }
  1072.  
  1073. ## Return the output for use in if statement
  1074.  
  1075. $output
  1076. }
  1077. Function registerWU-mshtml-dll {
  1078.  
  1079. $computername = "\\$computer"
  1080. $Scriptblock = "regsvr32.exe /s mshtml.dll"
  1081.  
  1082. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1083.  
  1084. ## Prepare the command line for PsExec. We use the XML output encoding so
  1085. ## that PowerShell can convert the output back into structured objects.
  1086. ## PowerShell expects that you pass it some input when being run by PsExec
  1087. ## this way, so the 'echo .' statement satisfies that appetite.
  1088. $commandLine = "echo . | powershell -Output XML "
  1089.  
  1090. ## Convert the command into an encoded command for PowerShell
  1091. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1092. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1093. $commandLine += "-EncodedCommand $encodedCommand"
  1094.  
  1095. ## Collect the output and error output
  1096. $errorOutput = [IO.Path]::GetTempFileName()
  1097. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1098.  
  1099. ## Check for any errors
  1100. $errorContent = Get-Content $errorOutput
  1101. Remove-Item $errorOutput
  1102. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1103. {
  1104.     $OFS = "`n"
  1105.     $errorMessage = "Could not execute remote expression. "
  1106.     $errorMessage += "Ensure that your account has administrative " +
  1107.         "privileges on the target machine.`n"
  1108.     $errorMessage += ($errorContent -match "psexec.exe :")
  1109.  
  1110.     Write-Error $errorMessage
  1111. }
  1112.  
  1113. ## Return the output for use in if statement
  1114.  
  1115. $output
  1116. }
  1117. Function registerWU-shdocvw-dll {
  1118.  
  1119. $computername = "\\$computer"
  1120. $Scriptblock = "regsvr32.exe /s shdocvw.dll"
  1121.  
  1122. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1123.  
  1124. ## Prepare the command line for PsExec. We use the XML output encoding so
  1125. ## that PowerShell can convert the output back into structured objects.
  1126. ## PowerShell expects that you pass it some input when being run by PsExec
  1127. ## this way, so the 'echo .' statement satisfies that appetite.
  1128. $commandLine = "echo . | powershell -Output XML "
  1129.  
  1130. ## Convert the command into an encoded command for PowerShell
  1131. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1132. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1133. $commandLine += "-EncodedCommand $encodedCommand"
  1134.  
  1135. ## Collect the output and error output
  1136. $errorOutput = [IO.Path]::GetTempFileName()
  1137. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1138.  
  1139. ## Check for any errors
  1140. $errorContent = Get-Content $errorOutput
  1141. Remove-Item $errorOutput
  1142. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1143. {
  1144.     $OFS = "`n"
  1145.     $errorMessage = "Could not execute remote expression. "
  1146.     $errorMessage += "Ensure that your account has administrative " +
  1147.         "privileges on the target machine.`n"
  1148.     $errorMessage += ($errorContent -match "psexec.exe :")
  1149.  
  1150.     Write-Error $errorMessage
  1151. }
  1152.  
  1153. ## Return the output for use in if statement
  1154.  
  1155. $output
  1156. }
  1157. Function registerWU-browseui-dll {
  1158.  
  1159. $computername = "\\$computer"
  1160. $Scriptblock = "regsvr32.exe /s browseui.dll"
  1161.  
  1162. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1163.  
  1164. ## Prepare the command line for PsExec. We use the XML output encoding so
  1165. ## that PowerShell can convert the output back into structured objects.
  1166. ## PowerShell expects that you pass it some input when being run by PsExec
  1167. ## this way, so the 'echo .' statement satisfies that appetite.
  1168. $commandLine = "echo . | powershell -Output XML "
  1169.  
  1170. ## Convert the command into an encoded command for PowerShell
  1171. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1172. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1173. $commandLine += "-EncodedCommand $encodedCommand"
  1174.  
  1175. ## Collect the output and error output
  1176. $errorOutput = [IO.Path]::GetTempFileName()
  1177. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1178.  
  1179. ## Check for any errors
  1180. $errorContent = Get-Content $errorOutput
  1181. Remove-Item $errorOutput
  1182. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1183. {
  1184.     $OFS = "`n"
  1185.     $errorMessage = "Could not execute remote expression. "
  1186.     $errorMessage += "Ensure that your account has administrative " +
  1187.         "privileges on the target machine.`n"
  1188.     $errorMessage += ($errorContent -match "psexec.exe :")
  1189.  
  1190.     Write-Error $errorMessage
  1191. }
  1192.  
  1193. ## Return the output for use in if statement
  1194.  
  1195. $output
  1196. }
  1197. Function registerWU-jscript-dll {
  1198.  
  1199. $computername = "\\$computer"
  1200. $Scriptblock = "regsvr32.exe /s jscript.dll"
  1201.  
  1202. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1203.  
  1204. ## Prepare the command line for PsExec. We use the XML output encoding so
  1205. ## that PowerShell can convert the output back into structured objects.
  1206. ## PowerShell expects that you pass it some input when being run by PsExec
  1207. ## this way, so the 'echo .' statement satisfies that appetite.
  1208. $commandLine = "echo . | powershell -Output XML "
  1209.  
  1210. ## Convert the command into an encoded command for PowerShell
  1211. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1212. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1213. $commandLine += "-EncodedCommand $encodedCommand"
  1214.  
  1215. ## Collect the output and error output
  1216. $errorOutput = [IO.Path]::GetTempFileName()
  1217. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1218.  
  1219. ## Check for any errors
  1220. $errorContent = Get-Content $errorOutput
  1221. Remove-Item $errorOutput
  1222. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1223. {
  1224.     $OFS = "`n"
  1225.     $errorMessage = "Could not execute remote expression. "
  1226.     $errorMessage += "Ensure that your account has administrative " +
  1227.         "privileges on the target machine.`n"
  1228.     $errorMessage += ($errorContent -match "psexec.exe :")
  1229.  
  1230.     Write-Error $errorMessage
  1231. }
  1232.  
  1233. ## Return the output for use in if statement
  1234.  
  1235. $output
  1236. }
  1237. Function registerWU-vbscript-dll {
  1238.  
  1239. $computername = "\\$computer"
  1240. $Scriptblock = "regsvr32.exe /s vbscript.dll"
  1241.  
  1242. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1243.  
  1244. ## Prepare the command line for PsExec. We use the XML output encoding so
  1245. ## that PowerShell can convert the output back into structured objects.
  1246. ## PowerShell expects that you pass it some input when being run by PsExec
  1247. ## this way, so the 'echo .' statement satisfies that appetite.
  1248. $commandLine = "echo . | powershell -Output XML "
  1249.  
  1250. ## Convert the command into an encoded command for PowerShell
  1251. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1252. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1253. $commandLine += "-EncodedCommand $encodedCommand"
  1254.  
  1255. ## Collect the output and error output
  1256. $errorOutput = [IO.Path]::GetTempFileName()
  1257. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1258.  
  1259. ## Check for any errors
  1260. $errorContent = Get-Content $errorOutput
  1261. Remove-Item $errorOutput
  1262. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1263. {
  1264.     $OFS = "`n"
  1265.     $errorMessage = "Could not execute remote expression. "
  1266.     $errorMessage += "Ensure that your account has administrative " +
  1267.         "privileges on the target machine.`n"
  1268.     $errorMessage += ($errorContent -match "psexec.exe :")
  1269.  
  1270.     Write-Error $errorMessage
  1271. }
  1272.  
  1273. ## Return the output for use in if statement
  1274.  
  1275. $output
  1276. }
  1277. Function registerWU-scrrun-dll {
  1278.  
  1279. $computername = "\\$computer"
  1280. $Scriptblock = "regsvr32.exe /s scrrun.dll"
  1281.  
  1282. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1283.  
  1284. ## Prepare the command line for PsExec. We use the XML output encoding so
  1285. ## that PowerShell can convert the output back into structured objects.
  1286. ## PowerShell expects that you pass it some input when being run by PsExec
  1287. ## this way, so the 'echo .' statement satisfies that appetite.
  1288. $commandLine = "echo . | powershell -Output XML "
  1289.  
  1290. ## Convert the command into an encoded command for PowerShell
  1291. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1292. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1293. $commandLine += "-EncodedCommand $encodedCommand"
  1294.  
  1295. ## Collect the output and error output
  1296. $errorOutput = [IO.Path]::GetTempFileName()
  1297. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1298.  
  1299. ## Check for any errors
  1300. $errorContent = Get-Content $errorOutput
  1301. Remove-Item $errorOutput
  1302. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1303. {
  1304.     $OFS = "`n"
  1305.     $errorMessage = "Could not execute remote expression. "
  1306.     $errorMessage += "Ensure that your account has administrative " +
  1307.         "privileges on the target machine.`n"
  1308.     $errorMessage += ($errorContent -match "psexec.exe :")
  1309.  
  1310.     Write-Error $errorMessage
  1311. }
  1312.  
  1313. ## Return the output for use in if statement
  1314.  
  1315. $output
  1316. }
  1317. Function registerWU-msxml-dll {
  1318.  
  1319. $computername = "\\$computer"
  1320. $Scriptblock = "regsvr32.exe /s msxml.dll"
  1321.  
  1322. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1323.  
  1324. ## Prepare the command line for PsExec. We use the XML output encoding so
  1325. ## that PowerShell can convert the output back into structured objects.
  1326. ## PowerShell expects that you pass it some input when being run by PsExec
  1327. ## this way, so the 'echo .' statement satisfies that appetite.
  1328. $commandLine = "echo . | powershell -Output XML "
  1329.  
  1330. ## Convert the command into an encoded command for PowerShell
  1331. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1332. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1333. $commandLine += "-EncodedCommand $encodedCommand"
  1334.  
  1335. ## Collect the output and error output
  1336. $errorOutput = [IO.Path]::GetTempFileName()
  1337. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1338.  
  1339. ## Check for any errors
  1340. $errorContent = Get-Content $errorOutput
  1341. Remove-Item $errorOutput
  1342. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1343. {
  1344.     $OFS = "`n"
  1345.     $errorMessage = "Could not execute remote expression. "
  1346.     $errorMessage += "Ensure that your account has administrative " +
  1347.         "privileges on the target machine.`n"
  1348.     $errorMessage += ($errorContent -match "psexec.exe :")
  1349.  
  1350.     Write-Error $errorMessage
  1351. }
  1352.  
  1353. ## Return the output for use in if statement
  1354.  
  1355. $output
  1356. }
  1357. Function registerWU-msxml3-dll {
  1358.  
  1359. $computername = "\\$computer"
  1360. $Scriptblock = "regsvr32.exe /s msxml3.dll"
  1361.  
  1362. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1363.  
  1364. ## Prepare the command line for PsExec. We use the XML output encoding so
  1365. ## that PowerShell can convert the output back into structured objects.
  1366. ## PowerShell expects that you pass it some input when being run by PsExec
  1367. ## this way, so the 'echo .' statement satisfies that appetite.
  1368. $commandLine = "echo . | powershell -Output XML "
  1369.  
  1370. ## Convert the command into an encoded command for PowerShell
  1371. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1372. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1373. $commandLine += "-EncodedCommand $encodedCommand"
  1374.  
  1375. ## Collect the output and error output
  1376. $errorOutput = [IO.Path]::GetTempFileName()
  1377. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1378.  
  1379. ## Check for any errors
  1380. $errorContent = Get-Content $errorOutput
  1381. Remove-Item $errorOutput
  1382. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1383. {
  1384.     $OFS = "`n"
  1385.     $errorMessage = "Could not execute remote expression. "
  1386.     $errorMessage += "Ensure that your account has administrative " +
  1387.         "privileges on the target machine.`n"
  1388.     $errorMessage += ($errorContent -match "psexec.exe :")
  1389.  
  1390.     Write-Error $errorMessage
  1391. }
  1392.  
  1393. ## Return the output for use in if statement
  1394.  
  1395. $output
  1396. }
  1397. Function registerWU-msxml6-dll {
  1398.  
  1399. $computername = "\\$computer"
  1400. $Scriptblock = "regsvr32.exe /s msxml6.dll"
  1401.  
  1402. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1403.  
  1404. ## Prepare the command line for PsExec. We use the XML output encoding so
  1405. ## that PowerShell can convert the output back into structured objects.
  1406. ## PowerShell expects that you pass it some input when being run by PsExec
  1407. ## this way, so the 'echo .' statement satisfies that appetite.
  1408. $commandLine = "echo . | powershell -Output XML "
  1409.  
  1410. ## Convert the command into an encoded command for PowerShell
  1411. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1412. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1413. $commandLine += "-EncodedCommand $encodedCommand"
  1414.  
  1415. ## Collect the output and error output
  1416. $errorOutput = [IO.Path]::GetTempFileName()
  1417. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1418.  
  1419. ## Check for any errors
  1420. $errorContent = Get-Content $errorOutput
  1421. Remove-Item $errorOutput
  1422. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1423. {
  1424.     $OFS = "`n"
  1425.     $errorMessage = "Could not execute remote expression. "
  1426.     $errorMessage += "Ensure that your account has administrative " +
  1427.         "privileges on the target machine.`n"
  1428.     $errorMessage += ($errorContent -match "psexec.exe :")
  1429.  
  1430.     Write-Error $errorMessage
  1431. }
  1432.  
  1433. ## Return the output for use in if statement
  1434.  
  1435. $output
  1436. }
  1437. Function registerWU-actxprxy-dll {
  1438.  
  1439. $computername = "\\$computer"
  1440. $Scriptblock = "regsvr32.exe /s actxprxy.dll"
  1441.  
  1442. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1443.  
  1444. ## Prepare the command line for PsExec. We use the XML output encoding so
  1445. ## that PowerShell can convert the output back into structured objects.
  1446. ## PowerShell expects that you pass it some input when being run by PsExec
  1447. ## this way, so the 'echo .' statement satisfies that appetite.
  1448. $commandLine = "echo . | powershell -Output XML "
  1449.  
  1450. ## Convert the command into an encoded command for PowerShell
  1451. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1452. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1453. $commandLine += "-EncodedCommand $encodedCommand"
  1454.  
  1455. ## Collect the output and error output
  1456. $errorOutput = [IO.Path]::GetTempFileName()
  1457. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1458.  
  1459. ## Check for any errors
  1460. $errorContent = Get-Content $errorOutput
  1461. Remove-Item $errorOutput
  1462. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1463. {
  1464.     $OFS = "`n"
  1465.     $errorMessage = "Could not execute remote expression. "
  1466.     $errorMessage += "Ensure that your account has administrative " +
  1467.         "privileges on the target machine.`n"
  1468.     $errorMessage += ($errorContent -match "psexec.exe :")
  1469.  
  1470.     Write-Error $errorMessage
  1471. }
  1472.  
  1473. ## Return the output for use in if statement
  1474.  
  1475. $output
  1476. }
  1477. Function registerWU-softpub-dll {
  1478.  
  1479. $computername = "\\$computer"
  1480. $Scriptblock = "regsvr32.exe /s softpub.dll"
  1481.  
  1482. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1483.  
  1484. ## Prepare the command line for PsExec. We use the XML output encoding so
  1485. ## that PowerShell can convert the output back into structured objects.
  1486. ## PowerShell expects that you pass it some input when being run by PsExec
  1487. ## this way, so the 'echo .' statement satisfies that appetite.
  1488. $commandLine = "echo . | powershell -Output XML "
  1489.  
  1490. ## Convert the command into an encoded command for PowerShell
  1491. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1492. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1493. $commandLine += "-EncodedCommand $encodedCommand"
  1494.  
  1495. ## Collect the output and error output
  1496. $errorOutput = [IO.Path]::GetTempFileName()
  1497. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1498.  
  1499. ## Check for any errors
  1500. $errorContent = Get-Content $errorOutput
  1501. Remove-Item $errorOutput
  1502. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1503. {
  1504.     $OFS = "`n"
  1505.     $errorMessage = "Could not execute remote expression. "
  1506.     $errorMessage += "Ensure that your account has administrative " +
  1507.         "privileges on the target machine.`n"
  1508.     $errorMessage += ($errorContent -match "psexec.exe :")
  1509.  
  1510.     Write-Error $errorMessage
  1511. }
  1512.  
  1513. ## Return the output for use in if statement
  1514.  
  1515. $output
  1516. }
  1517. Function registerWU-wintrust-dll {
  1518.  
  1519. $computername = "\\$computer"
  1520. $Scriptblock = "regsvr32.exe /s wintrust.dll"
  1521.  
  1522. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1523.  
  1524. ## Prepare the command line for PsExec. We use the XML output encoding so
  1525. ## that PowerShell can convert the output back into structured objects.
  1526. ## PowerShell expects that you pass it some input when being run by PsExec
  1527. ## this way, so the 'echo .' statement satisfies that appetite.
  1528. $commandLine = "echo . | powershell -Output XML "
  1529.  
  1530. ## Convert the command into an encoded command for PowerShell
  1531. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1532. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1533. $commandLine += "-EncodedCommand $encodedCommand"
  1534.  
  1535. ## Collect the output and error output
  1536. $errorOutput = [IO.Path]::GetTempFileName()
  1537. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1538.  
  1539. ## Check for any errors
  1540. $errorContent = Get-Content $errorOutput
  1541. Remove-Item $errorOutput
  1542. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1543. {
  1544.     $OFS = "`n"
  1545.     $errorMessage = "Could not execute remote expression. "
  1546.     $errorMessage += "Ensure that your account has administrative " +
  1547.         "privileges on the target machine.`n"
  1548.     $errorMessage += ($errorContent -match "psexec.exe :")
  1549.  
  1550.     Write-Error $errorMessage
  1551. }
  1552.  
  1553. ## Return the output for use in if statement
  1554.  
  1555. $output
  1556. }
  1557. Function registerWU-dssenh-dll {
  1558.  
  1559. $computername = "\\$computer"
  1560. $Scriptblock = "regsvr32.exe /s dssenh.dll"
  1561.  
  1562. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1563.  
  1564. ## Prepare the command line for PsExec. We use the XML output encoding so
  1565. ## that PowerShell can convert the output back into structured objects.
  1566. ## PowerShell expects that you pass it some input when being run by PsExec
  1567. ## this way, so the 'echo .' statement satisfies that appetite.
  1568. $commandLine = "echo . | powershell -Output XML "
  1569.  
  1570. ## Convert the command into an encoded command for PowerShell
  1571. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1572. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1573. $commandLine += "-EncodedCommand $encodedCommand"
  1574.  
  1575. ## Collect the output and error output
  1576. $errorOutput = [IO.Path]::GetTempFileName()
  1577. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1578.  
  1579. ## Check for any errors
  1580. $errorContent = Get-Content $errorOutput
  1581. Remove-Item $errorOutput
  1582. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1583. {
  1584.     $OFS = "`n"
  1585.     $errorMessage = "Could not execute remote expression. "
  1586.     $errorMessage += "Ensure that your account has administrative " +
  1587.         "privileges on the target machine.`n"
  1588.     $errorMessage += ($errorContent -match "psexec.exe :")
  1589.  
  1590.     Write-Error $errorMessage
  1591. }
  1592.  
  1593. ## Return the output for use in if statement
  1594.  
  1595. $output
  1596. }
  1597. Function registerWU-rsaenh-dll {
  1598.  
  1599. $computername = "\\$computer"
  1600. $Scriptblock = "regsvr32.exe /s rsaenh.dll"
  1601.  
  1602. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1603.  
  1604. ## Prepare the command line for PsExec. We use the XML output encoding so
  1605. ## that PowerShell can convert the output back into structured objects.
  1606. ## PowerShell expects that you pass it some input when being run by PsExec
  1607. ## this way, so the 'echo .' statement satisfies that appetite.
  1608. $commandLine = "echo . | powershell -Output XML "
  1609.  
  1610. ## Convert the command into an encoded command for PowerShell
  1611. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1612. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1613. $commandLine += "-EncodedCommand $encodedCommand"
  1614.  
  1615. ## Collect the output and error output
  1616. $errorOutput = [IO.Path]::GetTempFileName()
  1617. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1618.  
  1619. ## Check for any errors
  1620. $errorContent = Get-Content $errorOutput
  1621. Remove-Item $errorOutput
  1622. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1623. {
  1624.     $OFS = "`n"
  1625.     $errorMessage = "Could not execute remote expression. "
  1626.     $errorMessage += "Ensure that your account has administrative " +
  1627.         "privileges on the target machine.`n"
  1628.     $errorMessage += ($errorContent -match "psexec.exe :")
  1629.  
  1630.     Write-Error $errorMessage
  1631. }
  1632.  
  1633. ## Return the output for use in if statement
  1634.  
  1635. $output
  1636. }
  1637. Function registerWU-gpkcsp-dll {
  1638.  
  1639. $computername = "\\$computer"
  1640. $Scriptblock = "regsvr32.exe /s gpkcsp.dll"
  1641.  
  1642. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1643.  
  1644. ## Prepare the command line for PsExec. We use the XML output encoding so
  1645. ## that PowerShell can convert the output back into structured objects.
  1646. ## PowerShell expects that you pass it some input when being run by PsExec
  1647. ## this way, so the 'echo .' statement satisfies that appetite.
  1648. $commandLine = "echo . | powershell -Output XML "
  1649.  
  1650. ## Convert the command into an encoded command for PowerShell
  1651. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1652. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1653. $commandLine += "-EncodedCommand $encodedCommand"
  1654.  
  1655. ## Collect the output and error output
  1656. $errorOutput = [IO.Path]::GetTempFileName()
  1657. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1658.  
  1659. ## Check for any errors
  1660. $errorContent = Get-Content $errorOutput
  1661. Remove-Item $errorOutput
  1662. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1663. {
  1664.     $OFS = "`n"
  1665.     $errorMessage = "Could not execute remote expression. "
  1666.     $errorMessage += "Ensure that your account has administrative " +
  1667.         "privileges on the target machine.`n"
  1668.     $errorMessage += ($errorContent -match "psexec.exe :")
  1669.  
  1670.     Write-Error $errorMessage
  1671. }
  1672.  
  1673. ## Return the output for use in if statement
  1674.  
  1675. $output
  1676. }
  1677. Function registerWU-sccbase-dll {
  1678.  
  1679. $computername = "\\$computer"
  1680. $Scriptblock = "regsvr32.exe /s sccbase.dll"
  1681.  
  1682. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1683.  
  1684. ## Prepare the command line for PsExec. We use the XML output encoding so
  1685. ## that PowerShell can convert the output back into structured objects.
  1686. ## PowerShell expects that you pass it some input when being run by PsExec
  1687. ## this way, so the 'echo .' statement satisfies that appetite.
  1688. $commandLine = "echo . | powershell -Output XML "
  1689.  
  1690. ## Convert the command into an encoded command for PowerShell
  1691. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1692. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1693. $commandLine += "-EncodedCommand $encodedCommand"
  1694.  
  1695. ## Collect the output and error output
  1696. $errorOutput = [IO.Path]::GetTempFileName()
  1697. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1698.  
  1699. ## Check for any errors
  1700. $errorContent = Get-Content $errorOutput
  1701. Remove-Item $errorOutput
  1702. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1703. {
  1704.     $OFS = "`n"
  1705.     $errorMessage = "Could not execute remote expression. "
  1706.     $errorMessage += "Ensure that your account has administrative " +
  1707.         "privileges on the target machine.`n"
  1708.     $errorMessage += ($errorContent -match "psexec.exe :")
  1709.  
  1710.     Write-Error $errorMessage
  1711. }
  1712.  
  1713. ## Return the output for use in if statement
  1714.  
  1715. $output
  1716. }
  1717. Function registerWU-slbcsp-dll {
  1718.  
  1719. $computername = "\\$computer"
  1720. $Scriptblock = "regsvr32.exe /s slbcsp.dll"
  1721.  
  1722. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1723.  
  1724. ## Prepare the command line for PsExec. We use the XML output encoding so
  1725. ## that PowerShell can convert the output back into structured objects.
  1726. ## PowerShell expects that you pass it some input when being run by PsExec
  1727. ## this way, so the 'echo .' statement satisfies that appetite.
  1728. $commandLine = "echo . | powershell -Output XML "
  1729.  
  1730. ## Convert the command into an encoded command for PowerShell
  1731. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1732. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1733. $commandLine += "-EncodedCommand $encodedCommand"
  1734.  
  1735. ## Collect the output and error output
  1736. $errorOutput = [IO.Path]::GetTempFileName()
  1737. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1738.  
  1739. ## Check for any errors
  1740. $errorContent = Get-Content $errorOutput
  1741. Remove-Item $errorOutput
  1742. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1743. {
  1744.     $OFS = "`n"
  1745.     $errorMessage = "Could not execute remote expression. "
  1746.     $errorMessage += "Ensure that your account has administrative " +
  1747.         "privileges on the target machine.`n"
  1748.     $errorMessage += ($errorContent -match "psexec.exe :")
  1749.  
  1750.     Write-Error $errorMessage
  1751. }
  1752.  
  1753. ## Return the output for use in if statement
  1754.  
  1755. $output
  1756. }
  1757. Function registerWU-cryptdlg-dll {
  1758.  
  1759. $computername = "\\$computer"
  1760. $Scriptblock = "regsvr32.exe /s cryptdlg.dll"
  1761.  
  1762. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1763.  
  1764. ## Prepare the command line for PsExec. We use the XML output encoding so
  1765. ## that PowerShell can convert the output back into structured objects.
  1766. ## PowerShell expects that you pass it some input when being run by PsExec
  1767. ## this way, so the 'echo .' statement satisfies that appetite.
  1768. $commandLine = "echo . | powershell -Output XML "
  1769.  
  1770. ## Convert the command into an encoded command for PowerShell
  1771. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1772. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1773. $commandLine += "-EncodedCommand $encodedCommand"
  1774.  
  1775. ## Collect the output and error output
  1776. $errorOutput = [IO.Path]::GetTempFileName()
  1777. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1778.  
  1779. ## Check for any errors
  1780. $errorContent = Get-Content $errorOutput
  1781. Remove-Item $errorOutput
  1782. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1783. {
  1784.     $OFS = "`n"
  1785.     $errorMessage = "Could not execute remote expression. "
  1786.     $errorMessage += "Ensure that your account has administrative " +
  1787.         "privileges on the target machine.`n"
  1788.     $errorMessage += ($errorContent -match "psexec.exe :")
  1789.  
  1790.     Write-Error $errorMessage
  1791. }
  1792.  
  1793. ## Return the output for use in if statement
  1794.  
  1795. $output
  1796. }
  1797. Function registerWU-oleaut32-dll {
  1798.  
  1799. $computername = "\\$computer"
  1800. $Scriptblock = "regsvr32.exe /s oleaut32.dll"
  1801.  
  1802. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1803.  
  1804. ## Prepare the command line for PsExec. We use the XML output encoding so
  1805. ## that PowerShell can convert the output back into structured objects.
  1806. ## PowerShell expects that you pass it some input when being run by PsExec
  1807. ## this way, so the 'echo .' statement satisfies that appetite.
  1808. $commandLine = "echo . | powershell -Output XML "
  1809.  
  1810. ## Convert the command into an encoded command for PowerShell
  1811. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1812. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1813. $commandLine += "-EncodedCommand $encodedCommand"
  1814.  
  1815. ## Collect the output and error output
  1816. $errorOutput = [IO.Path]::GetTempFileName()
  1817. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1818.  
  1819. ## Check for any errors
  1820. $errorContent = Get-Content $errorOutput
  1821. Remove-Item $errorOutput
  1822. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1823. {
  1824.     $OFS = "`n"
  1825.     $errorMessage = "Could not execute remote expression. "
  1826.     $errorMessage += "Ensure that your account has administrative " +
  1827.         "privileges on the target machine.`n"
  1828.     $errorMessage += ($errorContent -match "psexec.exe :")
  1829.  
  1830.     Write-Error $errorMessage
  1831. }
  1832.  
  1833. ## Return the output for use in if statement
  1834.  
  1835. $output
  1836. }
  1837. Function registerWU-ole32-dll {
  1838.  
  1839. $computername = "\\$computer"
  1840. $Scriptblock = "regsvr32.exe /s ole32.dll"
  1841.  
  1842. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1843.  
  1844. ## Prepare the command line for PsExec. We use the XML output encoding so
  1845. ## that PowerShell can convert the output back into structured objects.
  1846. ## PowerShell expects that you pass it some input when being run by PsExec
  1847. ## this way, so the 'echo .' statement satisfies that appetite.
  1848. $commandLine = "echo . | powershell -Output XML "
  1849.  
  1850. ## Convert the command into an encoded command for PowerShell
  1851. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1852. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1853. $commandLine += "-EncodedCommand $encodedCommand"
  1854.  
  1855. ## Collect the output and error output
  1856. $errorOutput = [IO.Path]::GetTempFileName()
  1857. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1858.  
  1859. ## Check for any errors
  1860. $errorContent = Get-Content $errorOutput
  1861. Remove-Item $errorOutput
  1862. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1863. {
  1864.     $OFS = "`n"
  1865.     $errorMessage = "Could not execute remote expression. "
  1866.     $errorMessage += "Ensure that your account has administrative " +
  1867.         "privileges on the target machine.`n"
  1868.     $errorMessage += ($errorContent -match "psexec.exe :")
  1869.  
  1870.     Write-Error $errorMessage
  1871. }
  1872.  
  1873. ## Return the output for use in if statement
  1874.  
  1875. $output
  1876. }
  1877. Function registerWU-shell32-dll {
  1878.  
  1879. $computername = "\\$computer"
  1880. $Scriptblock = "regsvr32.exe /s shell32.dll"
  1881.  
  1882. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1883.  
  1884. ## Prepare the command line for PsExec. We use the XML output encoding so
  1885. ## that PowerShell can convert the output back into structured objects.
  1886. ## PowerShell expects that you pass it some input when being run by PsExec
  1887. ## this way, so the 'echo .' statement satisfies that appetite.
  1888. $commandLine = "echo . | powershell -Output XML "
  1889.  
  1890. ## Convert the command into an encoded command for PowerShell
  1891. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1892. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1893. $commandLine += "-EncodedCommand $encodedCommand"
  1894.  
  1895. ## Collect the output and error output
  1896. $errorOutput = [IO.Path]::GetTempFileName()
  1897. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1898.  
  1899. ## Check for any errors
  1900. $errorContent = Get-Content $errorOutput
  1901. Remove-Item $errorOutput
  1902. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1903. {
  1904.     $OFS = "`n"
  1905.     $errorMessage = "Could not execute remote expression. "
  1906.     $errorMessage += "Ensure that your account has administrative " +
  1907.         "privileges on the target machine.`n"
  1908.     $errorMessage += ($errorContent -match "psexec.exe :")
  1909.  
  1910.     Write-Error $errorMessage
  1911. }
  1912.  
  1913. ## Return the output for use in if statement
  1914.  
  1915. $output
  1916. }
  1917. Function registerWU-initpki-dll {
  1918.  
  1919. $computername = "\\$computer"
  1920. $Scriptblock = "regsvr32.exe /s initpki.dll"
  1921.  
  1922. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1923.  
  1924. ## Prepare the command line for PsExec. We use the XML output encoding so
  1925. ## that PowerShell can convert the output back into structured objects.
  1926. ## PowerShell expects that you pass it some input when being run by PsExec
  1927. ## this way, so the 'echo .' statement satisfies that appetite.
  1928. $commandLine = "echo . | powershell -Output XML "
  1929.  
  1930. ## Convert the command into an encoded command for PowerShell
  1931. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1932. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1933. $commandLine += "-EncodedCommand $encodedCommand"
  1934.  
  1935. ## Collect the output and error output
  1936. $errorOutput = [IO.Path]::GetTempFileName()
  1937. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1938.  
  1939. ## Check for any errors
  1940. $errorContent = Get-Content $errorOutput
  1941. Remove-Item $errorOutput
  1942. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1943. {
  1944.     $OFS = "`n"
  1945.     $errorMessage = "Could not execute remote expression. "
  1946.     $errorMessage += "Ensure that your account has administrative " +
  1947.         "privileges on the target machine.`n"
  1948.     $errorMessage += ($errorContent -match "psexec.exe :")
  1949.  
  1950.     Write-Error $errorMessage
  1951. }
  1952.  
  1953. ## Return the output for use in if statement
  1954.  
  1955. $output
  1956. }
  1957. Function registerWU-wuapi-dll {
  1958.  
  1959. $computername = "\\$computer"
  1960. $Scriptblock = "regsvr32.exe /s wuapi.dll"
  1961.  
  1962. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  1963.  
  1964. ## Prepare the command line for PsExec. We use the XML output encoding so
  1965. ## that PowerShell can convert the output back into structured objects.
  1966. ## PowerShell expects that you pass it some input when being run by PsExec
  1967. ## this way, so the 'echo .' statement satisfies that appetite.
  1968. $commandLine = "echo . | powershell -Output XML "
  1969.  
  1970. ## Convert the command into an encoded command for PowerShell
  1971. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  1972. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  1973. $commandLine += "-EncodedCommand $encodedCommand"
  1974.  
  1975. ## Collect the output and error output
  1976. $errorOutput = [IO.Path]::GetTempFileName()
  1977. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  1978.  
  1979. ## Check for any errors
  1980. $errorContent = Get-Content $errorOutput
  1981. Remove-Item $errorOutput
  1982. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  1983. {
  1984.     $OFS = "`n"
  1985.     $errorMessage = "Could not execute remote expression. "
  1986.     $errorMessage += "Ensure that your account has administrative " +
  1987.         "privileges on the target machine.`n"
  1988.     $errorMessage += ($errorContent -match "psexec.exe :")
  1989.  
  1990.     Write-Error $errorMessage
  1991. }
  1992.  
  1993. ## Return the output for use in if statement
  1994.  
  1995. $output
  1996. }
  1997. Function registerWU-wuaueng-dll {
  1998.  
  1999. $computername = "\\$computer"
  2000. $Scriptblock = "regsvr32.exe /s wuaueng.dll"
  2001.  
  2002. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2003.  
  2004. ## Prepare the command line for PsExec. We use the XML output encoding so
  2005. ## that PowerShell can convert the output back into structured objects.
  2006. ## PowerShell expects that you pass it some input when being run by PsExec
  2007. ## this way, so the 'echo .' statement satisfies that appetite.
  2008. $commandLine = "echo . | powershell -Output XML "
  2009.  
  2010. ## Convert the command into an encoded command for PowerShell
  2011. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2012. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2013. $commandLine += "-EncodedCommand $encodedCommand"
  2014.  
  2015. ## Collect the output and error output
  2016. $errorOutput = [IO.Path]::GetTempFileName()
  2017. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2018.  
  2019. ## Check for any errors
  2020. $errorContent = Get-Content $errorOutput
  2021. Remove-Item $errorOutput
  2022. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2023. {
  2024.     $OFS = "`n"
  2025.     $errorMessage = "Could not execute remote expression. "
  2026.     $errorMessage += "Ensure that your account has administrative " +
  2027.         "privileges on the target machine.`n"
  2028.     $errorMessage += ($errorContent -match "psexec.exe :")
  2029.  
  2030.     Write-Error $errorMessage
  2031. }
  2032.  
  2033. ## Return the output for use in if statement
  2034.  
  2035. $output
  2036. }
  2037. Function registerWU-wuaueng1-dll {
  2038.  
  2039. $computername = "\\$computer"
  2040. $Scriptblock = "regsvr32.exe /s wuaueng1.dll"
  2041.  
  2042. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2043.  
  2044. ## Prepare the command line for PsExec. We use the XML output encoding so
  2045. ## that PowerShell can convert the output back into structured objects.
  2046. ## PowerShell expects that you pass it some input when being run by PsExec
  2047. ## this way, so the 'echo .' statement satisfies that appetite.
  2048. $commandLine = "echo . | powershell -Output XML "
  2049.  
  2050. ## Convert the command into an encoded command for PowerShell
  2051. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2052. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2053. $commandLine += "-EncodedCommand $encodedCommand"
  2054.  
  2055. ## Collect the output and error output
  2056. $errorOutput = [IO.Path]::GetTempFileName()
  2057. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2058.  
  2059. ## Check for any errors
  2060. $errorContent = Get-Content $errorOutput
  2061. Remove-Item $errorOutput
  2062. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2063. {
  2064.     $OFS = "`n"
  2065.     $errorMessage = "Could not execute remote expression. "
  2066.     $errorMessage += "Ensure that your account has administrative " +
  2067.         "privileges on the target machine.`n"
  2068.     $errorMessage += ($errorContent -match "psexec.exe :")
  2069.  
  2070.     Write-Error $errorMessage
  2071. }
  2072. ## Return the output for use in if statement
  2073.  
  2074. $output
  2075. }
  2076. Function registerWU-wucltui-dll {
  2077.  
  2078. $computername = "\\$computer"
  2079. $Scriptblock = "regsvr32.exe /s wucltui.dll"
  2080.  
  2081. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2082.  
  2083. ## Prepare the command line for PsExec. We use the XML output encoding so
  2084. ## that PowerShell can convert the output back into structured objects.
  2085. ## PowerShell expects that you pass it some input when being run by PsExec
  2086. ## this way, so the 'echo .' statement satisfies that appetite.
  2087. $commandLine = "echo . | powershell -Output XML "
  2088.  
  2089. ## Convert the command into an encoded command for PowerShell
  2090. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2091. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2092. $commandLine += "-EncodedCommand $encodedCommand"
  2093.  
  2094. ## Collect the output and error output
  2095. $errorOutput = [IO.Path]::GetTempFileName()
  2096. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2097.  
  2098. ## Check for any errors
  2099. $errorContent = Get-Content $errorOutput
  2100. Remove-Item $errorOutput
  2101. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2102. {
  2103.     $OFS = "`n"
  2104.     $errorMessage = "Could not execute remote expression. "
  2105.     $errorMessage += "Ensure that your account has administrative " +
  2106.         "privileges on the target machine.`n"
  2107.     $errorMessage += ($errorContent -match "psexec.exe :")
  2108.  
  2109.     Write-Error $errorMessage
  2110. }
  2111. ## Return the output for use in if statement
  2112.  
  2113. $output
  2114. }
  2115. Function registerWU-wups-dll {
  2116.  
  2117. $computername = "\\$computer"
  2118. $Scriptblock = "regsvr32.exe /s wups.dll"
  2119.  
  2120. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2121.  
  2122. ## Prepare the command line for PsExec. We use the XML output encoding so
  2123. ## that PowerShell can convert the output back into structured objects.
  2124. ## PowerShell expects that you pass it some input when being run by PsExec
  2125. ## this way, so the 'echo .' statement satisfies that appetite.
  2126. $commandLine = "echo . | powershell -Output XML "
  2127.  
  2128. ## Convert the command into an encoded command for PowerShell
  2129. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2130. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2131. $commandLine += "-EncodedCommand $encodedCommand"
  2132.  
  2133. ## Collect the output and error output
  2134. $errorOutput = [IO.Path]::GetTempFileName()
  2135. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2136.  
  2137. ## Check for any errors
  2138. $errorContent = Get-Content $errorOutput
  2139. Remove-Item $errorOutput
  2140. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2141. {
  2142.     $OFS = "`n"
  2143.     $errorMessage = "Could not execute remote expression. "
  2144.     $errorMessage += "Ensure that your account has administrative " +
  2145.         "privileges on the target machine.`n"
  2146.     $errorMessage += ($errorContent -match "psexec.exe :")
  2147.  
  2148.     Write-Error $errorMessage
  2149. }
  2150. ## Return the output for use in if statement
  2151.  
  2152. $output
  2153. }
  2154. Function registerWU-wups2-dll {
  2155.  
  2156. $computername = "\\$computer"
  2157. $Scriptblock = "regsvr32.exe /s wups2.dll"
  2158.  
  2159. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2160.  
  2161. ## Prepare the command line for PsExec. We use the XML output encoding so
  2162. ## that PowerShell can convert the output back into structured objects.
  2163. ## PowerShell expects that you pass it some input when being run by PsExec
  2164. ## this way, so the 'echo .' statement satisfies that appetite.
  2165. $commandLine = "echo . | powershell -Output XML "
  2166.  
  2167. ## Convert the command into an encoded command for PowerShell
  2168. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2169. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2170. $commandLine += "-EncodedCommand $encodedCommand"
  2171.  
  2172. ## Collect the output and error output
  2173. $errorOutput = [IO.Path]::GetTempFileName()
  2174. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2175.  
  2176. ## Check for any errors
  2177. $errorContent = Get-Content $errorOutput
  2178. Remove-Item $errorOutput
  2179. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2180. {
  2181.     $OFS = "`n"
  2182.     $errorMessage = "Could not execute remote expression. "
  2183.     $errorMessage += "Ensure that your account has administrative " +
  2184.         "privileges on the target machine.`n"
  2185.     $errorMessage += ($errorContent -match "psexec.exe :")
  2186.  
  2187.     Write-Error $errorMessage
  2188. }
  2189. ## Return the output for use in if statement
  2190.  
  2191. $output
  2192. }
  2193. Function registerWU-wuweb-dll {
  2194.  
  2195. $computername = "\\$computer"
  2196. $Scriptblock = "regsvr32.exe /s wuweb.dll"
  2197.  
  2198. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2199.  
  2200. ## Prepare the command line for PsExec. We use the XML output encoding so
  2201. ## that PowerShell can convert the output back into structured objects.
  2202. ## PowerShell expects that you pass it some input when being run by PsExec
  2203. ## this way, so the 'echo .' statement satisfies that appetite.
  2204. $commandLine = "echo . | powershell -Output XML "
  2205.  
  2206. ## Convert the command into an encoded command for PowerShell
  2207. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2208. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2209. $commandLine += "-EncodedCommand $encodedCommand"
  2210.  
  2211. ## Collect the output and error output
  2212. $errorOutput = [IO.Path]::GetTempFileName()
  2213. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2214.  
  2215. ## Check for any errors
  2216. $errorContent = Get-Content $errorOutput
  2217. Remove-Item $errorOutput
  2218. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2219. {
  2220.     $OFS = "`n"
  2221.     $errorMessage = "Could not execute remote expression. "
  2222.     $errorMessage += "Ensure that your account has administrative " +
  2223.         "privileges on the target machine.`n"
  2224.     $errorMessage += ($errorContent -match "psexec.exe :")
  2225.  
  2226.     Write-Error $errorMessage
  2227. }
  2228. ## Return the output for use in if statement
  2229.  
  2230. $output
  2231. }
  2232. Function registerWU-qmgr-dll {
  2233.  
  2234. $computername = "\\$computer"
  2235. $Scriptblock = "regsvr32.exe /s qmgr.dll"
  2236.  
  2237. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2238.  
  2239. ## Prepare the command line for PsExec. We use the XML output encoding so
  2240. ## that PowerShell can convert the output back into structured objects.
  2241. ## PowerShell expects that you pass it some input when being run by PsExec
  2242. ## this way, so the 'echo .' statement satisfies that appetite.
  2243. $commandLine = "echo . | powershell -Output XML "
  2244.  
  2245. ## Convert the command into an encoded command for PowerShell
  2246. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2247. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2248. $commandLine += "-EncodedCommand $encodedCommand"
  2249.  
  2250. ## Collect the output and error output
  2251. $errorOutput = [IO.Path]::GetTempFileName()
  2252. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2253.  
  2254. ## Check for any errors
  2255. $errorContent = Get-Content $errorOutput
  2256. Remove-Item $errorOutput
  2257. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2258. {
  2259.     $OFS = "`n"
  2260.     $errorMessage = "Could not execute remote expression. "
  2261.     $errorMessage += "Ensure that your account has administrative " +
  2262.         "privileges on the target machine.`n"
  2263.     $errorMessage += ($errorContent -match "psexec.exe :")
  2264.  
  2265.     Write-Error $errorMessage
  2266. }
  2267. ## Return the output for use in if statement
  2268.  
  2269. $output
  2270. }
  2271. Function registerWU-qmgrprxy-dll {
  2272.  
  2273. $computername = "\\$computer"
  2274. $Scriptblock = "regsvr32.exe /s qmgrprxy.dll"
  2275.  
  2276. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2277.  
  2278. ## Prepare the command line for PsExec. We use the XML output encoding so
  2279. ## that PowerShell can convert the output back into structured objects.
  2280. ## PowerShell expects that you pass it some input when being run by PsExec
  2281. ## this way, so the 'echo .' statement satisfies that appetite.
  2282. $commandLine = "echo . | powershell -Output XML "
  2283.  
  2284. ## Convert the command into an encoded command for PowerShell
  2285. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2286. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2287. $commandLine += "-EncodedCommand $encodedCommand"
  2288.  
  2289. ## Collect the output and error output
  2290. $errorOutput = [IO.Path]::GetTempFileName()
  2291. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2292.  
  2293. ## Check for any errors
  2294. $errorContent = Get-Content $errorOutput
  2295. Remove-Item $errorOutput
  2296. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2297. {
  2298.     $OFS = "`n"
  2299.     $errorMessage = "Could not execute remote expression. "
  2300.     $errorMessage += "Ensure that your account has administrative " +
  2301.         "privileges on the target machine.`n"
  2302.     $errorMessage += ($errorContent -match "psexec.exe :")
  2303.  
  2304.     Write-Error $errorMessage
  2305. }
  2306. ## Return the output for use in if statement
  2307.  
  2308. $output
  2309. }
  2310. Function registerWU-wucltux-dll {
  2311.  
  2312. $computername = "\\$computer"
  2313. $Scriptblock = "regsvr32.exe /s wucltux.dll"
  2314.  
  2315. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2316.  
  2317. ## Prepare the command line for PsExec. We use the XML output encoding so
  2318. ## that PowerShell can convert the output back into structured objects.
  2319. ## PowerShell expects that you pass it some input when being run by PsExec
  2320. ## this way, so the 'echo .' statement satisfies that appetite.
  2321. $commandLine = "echo . | powershell -Output XML "
  2322.  
  2323. ## Convert the command into an encoded command for PowerShell
  2324. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2325. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2326. $commandLine += "-EncodedCommand $encodedCommand"
  2327.  
  2328. ## Collect the output and error output
  2329. $errorOutput = [IO.Path]::GetTempFileName()
  2330. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2331.  
  2332. ## Check for any errors
  2333. $errorContent = Get-Content $errorOutput
  2334. Remove-Item $errorOutput
  2335. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2336. {
  2337.     $OFS = "`n"
  2338.     $errorMessage = "Could not execute remote expression. "
  2339.     $errorMessage += "Ensure that your account has administrative " +
  2340.         "privileges on the target machine.`n"
  2341.     $errorMessage += ($errorContent -match "psexec.exe :")
  2342.  
  2343.     Write-Error $errorMessage
  2344. }
  2345. ## Return the output for use in if statement
  2346.  
  2347. $output
  2348. }
  2349. Function registerWU-muweb-dll {
  2350.  
  2351. $computername = "\\$computer"
  2352. $Scriptblock = "regsvr32.exe /s muweb.dll"
  2353.  
  2354. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2355.  
  2356. ## Prepare the command line for PsExec. We use the XML output encoding so
  2357. ## that PowerShell can convert the output back into structured objects.
  2358. ## PowerShell expects that you pass it some input when being run by PsExec
  2359. ## this way, so the 'echo .' statement satisfies that appetite.
  2360. $commandLine = "echo . | powershell -Output XML "
  2361.  
  2362. ## Convert the command into an encoded command for PowerShell
  2363. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2364. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2365. $commandLine += "-EncodedCommand $encodedCommand"
  2366.  
  2367. ## Collect the output and error output
  2368. $errorOutput = [IO.Path]::GetTempFileName()
  2369. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2370.  
  2371. ## Check for any errors
  2372. $errorContent = Get-Content $errorOutput
  2373. Remove-Item $errorOutput
  2374. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2375. {
  2376.     $OFS = "`n"
  2377.     $errorMessage = "Could not execute remote expression. "
  2378.     $errorMessage += "Ensure that your account has administrative " +
  2379.         "privileges on the target machine.`n"
  2380.     $errorMessage += ($errorContent -match "psexec.exe :")
  2381.  
  2382.     Write-Error $errorMessage
  2383. }
  2384. ## Return the output for use in if statement
  2385.  
  2386. $output
  2387. }
  2388. Function registerWU-wuwebv-dll {
  2389.  
  2390. $computername = "\\$computer"
  2391. $Scriptblock = "regsvr32.exe /s wuwebv.dll"
  2392.  
  2393. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor yellow $Computer "Attempting $Scriptblock"
  2394.  
  2395. ## Prepare the command line for PsExec. We use the XML output encoding so
  2396. ## that PowerShell can convert the output back into structured objects.
  2397. ## PowerShell expects that you pass it some input when being run by PsExec
  2398. ## this way, so the 'echo .' statement satisfies that appetite.
  2399. $commandLine = "echo . | powershell -Output XML "
  2400.  
  2401. ## Convert the command into an encoded command for PowerShell
  2402. $commandBytes = [System.Text.Encoding]::Unicode.GetBytes($scriptblock)
  2403. $encodedCommand = [Convert]::ToBase64String($commandBytes)
  2404. $commandLine += "-EncodedCommand $encodedCommand"
  2405.  
  2406. ## Collect the output and error output
  2407. $errorOutput = [IO.Path]::GetTempFileName()
  2408. $output = psexec /acceptEula $computername cmd /c $commandLine 2>$errorOutput
  2409.  
  2410. ## Check for any errors
  2411. $errorContent = Get-Content $errorOutput
  2412. Remove-Item $errorOutput
  2413. if($errorContent -match "(Access is denied)|(failure)|(Couldn't)")
  2414. {
  2415.     $OFS = "`n"
  2416.     $errorMessage = "Could not execute remote expression. "
  2417.     $errorMessage += "Ensure that your account has administrative " +
  2418.         "privileges on the target machine.`n"
  2419.     $errorMessage += ($errorContent -match "psexec.exe :")
  2420.  
  2421.     Write-Error $errorMessage
  2422. }
  2423. ## Return the output for use in if statement
  2424.  
  2425. $output
  2426. }
  2427. Function IsItStillPinging {
  2428. if (Test-Connection -computername $Computer  -count 1 -quiet)
  2429. {Return $True}
  2430.         else {
  2431.         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "LOST CONNECTION"
  2432.         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "LOST CONNECTION"
  2433.         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $Computer "LOST CONNECTION"
  2434.         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "LOST CONNECTION"
  2435.        
  2436.         Write-Output "$Computer, Lost Connection!, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  2437.         Return $False}
  2438. }
  2439.  
  2440. #--------------------------------------------------------------------------------------------
  2441. #                   MAIN            SCRIPT          ACTIONS
  2442. #--------------------------------------------------------------------------------------------
  2443. # Get our list of machines if it exists..
  2444. #--------------------------------------------------------------------------------------------
  2445. if (test-path -path "$inputfile" -erroraction SilentlyContinue) {
  2446. Write-Host -foregroundcolor Green "Found: $Inputfile"
  2447. $MasterList = gc $inputfile
  2448.     if ($MasterList -ne $null) {
  2449.     Write-Host -foregroundcolor cyan "Working from this list to clean based on WMI Success/Failure:"
  2450.     $MasterList
  2451.     Start-sleep -seconds 2
  2452.     #----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
  2453.     #
  2454.     #
  2455.     #                                       (Multi threaded) TESTING TO CLEAN MASTER LIST OF WMI FAILURES, REPORT ON THEM TO SHELL and LOG FILE and THEN fill $computers variable with ONLY the successful WMI checks.
  2456.     #
  2457.     #
  2458.     #----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
  2459.  
  2460.     .\MultiThread\Run-CommandMultiThreaded.ps1 -Command "Verify-WMI" -InputParam computername -ObjectList $Masterlist
  2461.  
  2462.     # $Computers Variable equals the current content of the $successfulResults variable.
  2463.     $Computers = $SuccessfulResults
  2464.  
  2465.     #----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
  2466.     #
  2467.     #
  2468.     #                                                       END OF TESTING TO CLEAN MASTER LIST OF WMI FAILURES
  2469.     #
  2470.     #
  2471.     #----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
  2472.  
  2473.     # start iteration at 1
  2474.     $Iteration = 1
  2475.  
  2476.     # fill $Total with the count of computers we're going to work from
  2477.     $Total = $Computers.count
  2478.  
  2479.         #-----------------------------------#
  2480.         #-----------------------------------#
  2481.         #-----------------------------------#
  2482.         #        START MAIN Foreach
  2483.         #-----------------------------------#
  2484.         #-----------------------------------#
  2485.         #-----------------------------------#
  2486.         ForEach ($Computer in $Computers) {
  2487.             # Set a value we can change later if things fail to do what we want them to and we want to halt the script.
  2488.             # as of writing NO functions cause the script to fail.
  2489.             $Continue = $True
  2490.  
  2491.             # more stolen secrets of the gods from Ken Hamilton RE: iteration
  2492.             $i = "{0:D4}" -f $Iteration
  2493.             $t = "{0:D4}" -f $Total
  2494.             if($WriteHost -eq $True){Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor cyan "$i of $t`t$($Computer.Name)"}
  2495.            
  2496.             # now that we've written the current machine's iteration, we increment that number so when the next machine goes through the loop, the number has gone up.
  2497.             $Iteration++
  2498.  
  2499.             # Write to log we are starting the process of remediation for this machine.
  2500.             Write-Output "$Computer, Starting Process, start,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  2501.  
  2502.             # Test to see if machine is pingable and only continue if it is
  2503.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "yellow" $Computer "Testing network connection"
  2504.            
  2505.             If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
  2506.                 Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "Green" ($Computer + " is pingable")
  2507.  
  2508.                 # Since we've determined WMI should work... this command should work to determine OS... If supported operating system, then continue:
  2509.                 $OS = Get-WmiObject -ComputerName $computer -Class Win32_OperatingSystem
  2510.                 if ($OS.Caption -notlike "*2003*" -and $OS.Caption -notlike "*XP*" -and $OS.Caption -notlike "*10*") {
  2511.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor green $Computer $OS.Caption
  2512.                     # if it's a supported operating system, then do our functions...
  2513.                     do {
  2514.                         #Copy-SCCMClientInstallation
  2515.                                                
  2516.                         #Stop-BitsIfItExists
  2517.                         #Stop-WuauservIfItExists
  2518.                         #Stop-appidsvcIfItExists
  2519.                         #Stop-cryptsvcIfItExists
  2520.                         #Stop-ccmexecIfItExists
  2521.  
  2522.                         #Remove-qmgrdatfiles
  2523.                         #Remove-WUSoftwareDistributionFolder
  2524.                         #Rename-WUSoftwareDistributionFolder
  2525.                         #Remove-CatRoot2Folder
  2526.                                                
  2527.                         #Reset-security-descriptor-bits
  2528.                         #Reset-security-descriptor-wuauserv
  2529.                                              
  2530.                         #registerWU-atl-dll
  2531.                         #registerWU-urlmon-dll
  2532.                         #registerWU-mshtml-dll
  2533.                         #registerWU-shdocvw-dll
  2534.                         #registerWU-browseui-dll
  2535.                         #registerWU-jscript-dll
  2536.                         #registerWU-vbscript-dll
  2537.                         #registerWU-scrrun-dll
  2538.                         #registerWU-msxml-dll
  2539.                         #registerWU-msxml3-dll
  2540.                         #registerWU-msxml6-dll
  2541.                         #registerWU-actxprxy-dll
  2542.                         #registerWU-softpub-dll
  2543.                         #registerWU-wintrust-dll
  2544.                         #registerWU-dssenh-dll
  2545.                         #registerWU-rsaenh-dll
  2546.                         #registerWU-gpkcsp-dll
  2547.                         #registerWU-sccbase-dll
  2548.                         #registerWU-slbcsp-dll
  2549.                         #registerWU-cryptdlg-dll
  2550.                         #registerWU-oleaut32-dll
  2551.                         #registerWU-ole32-dll
  2552.                         #registerWU-shell32-dll
  2553.                         #registerWU-initpki-dll
  2554.                         #registerWU-wuapi-dll
  2555.                         #registerWU-wuaueng-dll
  2556.                         #registerWU-wuaueng1-dll
  2557.                         #registerWU-wucltui-dll
  2558.                         #registerWU-wups-dll
  2559.                         #registerWU-wups2-dll
  2560.                         #registerWU-wuweb-dll
  2561.                         #registerWU-qmgr-dll
  2562.                         #registerWU-qmgrprxy-dll
  2563.                         #registerWU-wucltux-dll
  2564.                         #registerWU-muweb-dll
  2565.                         #registerWU-wuwebv-dll
  2566.  
  2567.                         #Start-BitsIfItExists
  2568.                         #Start-WuauservIfItExists
  2569.                         #Start-AppIDsvcIfItExists
  2570.                         #Start-CryptSvcIfItExists
  2571.  
  2572.                         #reset-Bitsadmin
  2573.  
  2574.                         #Remove-CCMCacheFolder
  2575.  
  2576.                         #Uninstall-SCCMClient
  2577.                                                
  2578.                         #Remove-CCMSetupFolder
  2579.                         #Remove-CCMFolder
  2580.                         #Remove-CCMNamespace
  2581.                         #Remove-SMSNamespace
  2582.                                                
  2583.                         #Install-SCCMClient
  2584.  
  2585.                         #Force-WUAgentDetectnow
  2586.                         $Continue = $False
  2587.                         } while ($Continue -eq $True)
  2588.                     # If theres a log file/s open for that machine in trace32, (we do the if because i dunno maybe someone closed it, or it's failed to open properly or something) wait 5 seconds and close it/them.
  2589.                     # also don't want to close someone's log of looking at another pc >_> which is annoying and has happened to me a lot...
  2590.                     if (Get-process trace32 | where {$_.MainWindowTitle -like "*$Computer*"}) {
  2591.                         $seconds = 5
  2592.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") "$Computer Exiting log in $seconds seconds"
  2593.                         Start-sleep -seconds $seconds
  2594.                         Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "green" $Computer "Exiting Log"
  2595.                         $process = get-process trace32 | where {$_.MainWindowTitle -like "*$Computer*"}
  2596.                         $Process | Stop-Process
  2597.                     }
  2598.                 }
  2599.                 Write-Output "$Computer, Ending Process, end,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  2600.                 # Start of ELSE in OS Checking IF statement
  2601.                 else {
  2602.                     # OS type Unsupported..
  2603.                     Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor Red $Computer "This machine will not be processed, Reason: Unsupported Machine Type: "$OS.Caption
  2604.                     Write-Output "$Computer, Unsupported Machine Type: $OS.Caption, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  2605.                     Write-Output "$Computer, Ending Process, end,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  2606.                 }
  2607.             }
  2608.             #ping fails:
  2609.             else {
  2610.             Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor "red" $computer "Ping FAILED - machine offline or not listening for ICMP"
  2611.             Write-Output "$Computer, Failed to Ping - Machine offline or not listening for ICMP, error,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  2612.             Write-Output "$Computer, Ending Process, end,$(Get-Date -format "dd_MM_yyyy_HH:mm:ss")" | Add_To_Log
  2613.             }
  2614.         }
  2615.         #-----------------------------------#
  2616.         #-----------------------------------#
  2617.         #-----------------------------------#
  2618.         #        END MAIN Foreach
  2619.         #-----------------------------------#
  2620.         #-----------------------------------#
  2621.         #-----------------------------------#
  2622.     }
  2623.     # End if - master list had content
  2624.     else {
  2625.     #Input file was empty?
  2626.     Write-Host -foregroundcolor red "InputFile empty?"
  2627.     }
  2628. }
  2629. else {
  2630. # no input file even exists...
  2631. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") -foregroundcolor red "No servers.txt file found in: $WorkingDirectory\Input\"
  2632. }
  2633.  
  2634. #--------------------------------------------------------------------------------------------
  2635. #                   MAIN            SCRIPT          ACTIONS
  2636. #--------------------------------------------------------------------------------------------
  2637.  
  2638. # Write where a user can get the log from...
  2639. Write-Host $(Get-Date -format "dd_MM_yyyy_HH:mm:ss") "Output file saved here: $resultfile"
  2640.  
  2641. # Then because i'm lazy i want it to open for them...
  2642. Start-Sleep -seconds 2
  2643. explorer.exe $logfolder
  2644. ## END OF SCRIPT
RAW Paste Data