Thursday 29 October 2009

Restart-DNS.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script restarts the DNS Service on a Remote System 
  4. .DESCRIPTION 
  5.     This script uses WMI to reach out and restart the DNS 
  6.     DNS service on a remote machine. in my home environment, 
  7.     I find the DNS service on the home DC fails and needs  
  8.     to be restarted - this script works! 
  9. .NOTES 
  10.     File Name  : Restart-DNS.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell V2 
  13. .LINK 
  14.     This script posted to: 
  15.         http://pshscripts.blogspot.com/2009/10/restart-dnsps1.html
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Restart-DNS.ps1 
  18.     Restarting DNS Service on: Cookham1 
  19.     DNS Service stopped 
  20.     DNS Service started 
  21. #> 
  22. ## 
  23. # Start Script 
  24. ## 
  25.  
  26. # Set server to reset and display our intention 
  27. $Server = "Cookham1" 
  28. "Restarting DNS Service on: $Server" 
  29.   
  30. # Get DNS service 
  31. $dns = gwmi win32_service -computer $Server  | where {$_.name -eq "DNS"
  32.   
  33. # Now stop it 
  34. $ret = $dns.stopservice() 
  35. if ($ret.returnvalue -eq 0) {"DNS Service stopped"
  36. else {"DNS Service not stopped"
  37.   
  38. # And now restart it 
  39. $ret = $dns.startservice() 
  40. if ($ret.returnvalue -eq 0) {"DNS Service started"
  41. else {"DNS Service not started"
  42.   
  43. # End of Script 
Technorati Tags: ,,,,

No comments: