# Ps1 script to reset WSUS authorization
cls
# Specify computers to reset WSUS authorization
$NoInWSUS = @
(
   'localhost'
   #'computer1.yourdomain.com',
   #'computer2.yourdomain.com',
   #'computer2.yourdomain.com'
)

# ping computer
function Test-Host ($Name)
{
   $ping = new-object System.Net.NetworkInformation.Ping
   trap {Write-Host "Ping error = " + $Name; $False; continue}
   if ($ping.send($Name).Status -eq "Success" ) { $True }
   else { $False }
}


$NoInWSUS | where{Test-Host $_}|foreach {	
		
   $h = $_    	
   $command = 
   {       
      param($h) 	
      # Connect to wuauserv service   
      [System.Reflection.Assembly]::LoadWithPartialName('system.serviceprocess')
      $wuauserv = new-Object System.ServiceProcess.ServiceController('wuauserv',$h)
      # Flag initialization to stop wuauserv service
      $Stopped = $true
       	   
      if ($wuauserv.Status -ne "Stopped") 
      {
         try 
	 {               
	    # Stop wuauserv service and wait 10 seconds when the service is stopped
	    $wuauserv.Stop()               
	    $wuauserv.WaitForStatus('Stopped',(new-timespan -seconds 10))
	 }
	 catch 
	 {               
	    # Change flag if wuauserv service is not stopped after timeout
	    $Stopped = $false
         }
      }
      # If wuauserv service is stopped then we do actions from Microsoft KB903262
      if ($Stopped) 
      {          
 	 # Remove registry keys         
	 Remove-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate' -Name SusClientId
	 Remove-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate' -Name SusClientIdValidation
      }
      # Flag initialization to start wuauserv service
      $Started = $true       
      try
      {
  	 # Start wuauserv service and wait when the service is running
	 $wuauserv.Start()          
	 $wuauserv.WaitForStatus('Running',(new-timespan -seconds 10))
      }
      catch 
      {          
         # Change flag if wuauserv service is not running after timeout  
	 $Started = $false
      }       
      # If wuauserv service is running then we do actions from Microsoft KB903262
      if ($Started) 
      {
         # Wait 5 seconds
	 Start-Sleep -Seconds 5
	 # Do command gpupdate /force           
	 $RemoteProcess = ([wmiclass]"\\$h\root\cimv2:Win32_Process").create("cmd /c gpupdate /force")
	 Start-Sleep -Seconds 30
	 # Do command wuauclt /resetauthorization /detectnow (source - http://support.microsoft.com/kb/903262)
	 $RemoteProcess = ([wmiclass]"\\$h\root\cimv2:Win32_Process").create("cmd /c wuauclt /resetauthorization /detectnow")        
      }
   }		
			 
   # If your computers are ready for Windows Remoting technology  then use invoke-command to do 
   # $command remotely on computers specified in $NoInWSUS array.  	
   invoke-command -computername $h -scriptblock $command -ArgumentList $h	   	
	
   # If not - please comment the line above, remove comment from the line below, remove all lines in 
   # $NoInWSUS (except 'localhost') and start the script directly on the computer with admin priveleges 	
   # $command	
}