Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #Run - Get-Cluster CLUSTERNAME | Get-VM | Select Name | Sort Name | Export-Csv ./CLUSTERNAME.csv -NoTypeInformation
  2. $clusterVMs = Import-Csv '.\ASMCL06.csv'
  3. $KB = "KB2982791"
  4. $KBNumber = $KB.Replace("KB", "")
  5. $RemovalCommand = "wusa.exe /uninstall /kb:$KBNumber /quiet /norestart"
  6. $Domain = "corp.local"
  7.  
  8. $report = @()
  9.  
  10. $clusterVMs | % {
  11.  
  12. $computerName ="$($_.Name).$($Domain)"
  13.  
  14. $reportObject = New-Object PSObject
  15. Add-Member -InputObject $reportObject -MemberType NoteProperty -Name Name -Value $computerName
  16.  
  17. Write-Host "Processing $computername " -NoNewLine
  18.  
  19. try {
  20.  
  21. $result = Invoke-Command -ComputerName $computerName -ScriptBlock {
  22.  
  23. if ((Get-Hotfix -Id $Using:KB -ErrorAction SilentlyContinue)){
  24.  
  25. Invoke-Expression -Command $Using:RemovalCommand
  26.  
  27. while ($true) {
  28.  
  29. Start-Sleep 3
  30.  
  31. if ((Get-Process | Where-Object {$_.name -eq "wusa"}).Count -eq 0 -or (Get-Process | Where-Object {$_.name -eq "wusa"}).Count -eq $null){
  32.  
  33. break
  34.  
  35. }
  36. }
  37.  
  38. if (!(Get-Hotfix -Id $Using:KB -ErrorAction SilentlyContinue)){
  39.  
  40. Write-Host "|KB Removed|" -ForegroundColor GREEN
  41. $result = "KB Removed"
  42.  
  43. }
  44.  
  45. }
  46.  
  47. else {
  48.  
  49. Write-Host "|Could not find KB|" -ForegroundColor GREEN
  50. $result = "Could not find KB"
  51.  
  52. }
  53.  
  54. #Return result here
  55. $result
  56.  
  57. } -ErrorAction Stop
  58.  
  59. Add-Member -InputObject $reportObject -MemberType NoteProperty -Name KBRemoval -Value $result
  60.  
  61. }
  62. catch [Exception] {
  63.  
  64. Write-Host "|Failed!|" -ForegroundColor RED
  65. Add-Member -InputObject $reportObject -MemberType NoteProperty -Name KBRemoval -Value $_.Exception.Message
  66.  
  67. }
  68.  
  69. #Add each new object to the report array
  70. $report += $reportObject
  71.  
  72. }
  73.  
  74. #Export the array to CSV
  75. $report | Export-Csv -Path "./hotfixReport-$(Get-Date -Format ttMMyyyHHmmSS).csv" -NoTypeInformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement