Thursday 7 October 2010

Get-WMINameSpace.ps1


  1. <# 
  2. .SYNOPSIS 
  3.     This script displays all the WMI namespaces within a Windows system 
  4. .DESCRIPTION 
  5.     This script uses Get-WMIObject to retrieve the names of all the namespaces 
  6.     within a system. 
  7. .NOTES 
  8.     File Name  : Get-WMINameSpace.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to:
  13.         http://pshscripts.blogspot.com/2010/10/get-wminamespaceps1.html
  14. .EXAMPLE 
  15.     PSH [C:\foo]: .\Get-WMINameSpace.ps1 
  16.     37 Namespaces on: Cookham8 
  17.  
  18.     Namespace 
  19.     --------- 
  20.     ROOT 
  21.     ROOT\aspnet 
  22.     ROOT\CIMV2 
  23.     ROOT\CIMV2\Security 
  24.     ROOT\CIMV2\Security\MicrosoftTpm 
  25.     ... {Remainder of list snipped to save space on this page} 
  26. #> 
  27.  
  28. # Set computer name
  29. $comp = "." 
  30. # Get the name spaces on the local computer, and the local computer name 
  31. $Namespace = get-wmiobject __namespace -namespace 'root' -list -recurse -computer $comp  
  32. $hostname = hostname 
  33.  
  34. # Display number of and names of the namespaces 
  35. "{0} Namespaces on: {1}" -f $namespace.count, $hostname 
  36. $NameSpace| sort __namespace  | Format-Table @{Expression = "__Namespace"; Label = "Namespace"
Technorati Tags: ,,,

Wednesday 6 October 2010

Get-LoopBack.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script checks whether a parameter is a Loopback Address  
  4. .DESCRIPTION 
  5.     This script checks to see if the passsed string is an IPV4
  6.     or an IPv6 loopback address and if so, displays details.
  7. .NOTES 
  8.     File Name  : Get-LoopBack.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com  
  14.     MSDN sample posted to: 
  15.         http://msdn.microsoft.com/en-us/library/system.net.ipaddress.isloopback.aspx  
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Get-LoopBack.ps1 
  18.     Your input address: \127.0.0.1\ is an IPv4 loopback address whose internal format is: 127.0.0.1. 
  19. .EXAMPLE 
  20.     PSH [C:\foo]: .\Get-LoopBack.ps1 ::1 
  21.     Your input address: \::1\ is an IPv6 loopback address whose internal format is: ::1. 
  22. .EXAMPLE 
  23.     PSH [C:\foo]: .\Get-LoopBack.ps1 131.107.2.200 
  24.     Your input address: \131.107.2.200\ is not a loopback address. 
  25. .PARAM 
  26.     $IPAddress - Address to look up to see if it's Loopback 
  27. #> 
  28. param
  29. [String] $IpAddress = "127.0.0.1" 
  30. )  
  31. # Setup Default answer! 
  32. $loopBack=" is not a loopback address."
  33.  
  34. # Perform syntax check by parsing the address string entered by the user. 
  35. $Address = [System.Net.IPAddress]::Parse($IpAddress); 
  36.  
  37. # Perform semantic check by verifying that the address is a valid IPv4  
  38. # or IPv6 loopback address.  
  39. if([System.Net.IPAddress]::IsLoopback($Address) -and ($address.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetworkV6) ) { 
  40.         $loopBack" is an IPv6 loopback address "
  41.                     "whose internal format is: " + $Address.ToString() + "."
  42. }            

Tuesday 5 October 2010

Get-HostByName.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets and displays basic DNS Information about a host. 
  4. .DESCRIPTION 
  5.     This script just gets and displays host details returnd by GetHostByName. 
  6. .NOTES 
  7.     File Name  : Get-ByName.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN sample posted tot: 
  14.         http://msdn.microsoft.com/en-us/library/system.net.dns.aspx 
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Get-HostByName.ps1 
  17.  
  18.     HostName    : contoso.com 
  19.     Aliases     : {www.contoso.com} 
  20.     AddressList : {207.46.197.32, 207.46.232.182} 
  21. #> 
  22. $hostInfo = [system.net.Dns]::GetHostByName("www.contoso.com"); 
  23. $hostinfo | fl * -force 

Monday 4 October 2010

Remove-FtpFile.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script deletes a file from an FTP Server 
  4. .DESCRIPTION 
  5.     This script is a rewrite of an MSDN Sample 
  6. .NOTES 
  7.     File Name  : Remove-FtpFile.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN sample posted tot: 
  14.         http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx 
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Remove-FtpFile.ps1 
  17.     Delete status: 250 DELE command successful. 
  18. #> 
  19. $ServerUri = New-Object System.Uri "ftp://www.reskit.net/powershell/foo.txt" 
  20. # The serverUri parameter should use the ftp:// scheme. 
  21. # It contains the name of the server file that is to be deleted. 
  22. # Example: ftp://contoso.com/someFile.txt. 
  23.  
  24. if ($ServerUri.Scheme -ne [system.Uri]::UriSchemeFtp) { 
  25.         " Bad URI"; return 
  26.  
  27. # Get the object used to communicate with the server. 
  28. $request = [system.Net.FtpWebRequest]::Create($serverUri
  29. $request.Method = [System.Net.WebRequestMethods+ftp]::Deletefile 
  30. $Request.Credentials = New-Object System.Net.NetworkCredential "anonymous","tfl@psp.co.uk" 
  31.  
  32. $response = $request.GetResponse() 
  33. "Delete status: {0}" -f $response.StatusDescription 
  34. $response.Close(); 

Sunday 3 October 2010

Copy-FileToFtp.ps1


  1. <# 
  2. .SYNOPSIS 
  3.     This script Uploads a text file to an FTP Server using PowerShell.  
  4. .DESCRIPTION 
  5.     This script first creates an FTP 'web' request to upload a file. Then the  
  6.     source file is read from disk and written up to the FTP Server. A response 
  7.     is then displayed. This is a rewrite of an MSDN Sample. 
  8. .NOTES 
  9.     File Name  : Copy-FileToFtp.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://pshscripts.blogspot.com/2010/10/copy-filetoftpps1.html
  15.     MSDN sample posted tot: 
  16.         http://msdn.microsoft.com/en-us/library/ms229715.aspx
  17. .EXAMPLE 
  18.     PSH [C:\foo]: .Copy-FileToFtp.ps1 
  19.     Upload File Complete, status 226
  20.     226 Transfer complete. 
  21. #> 
  22.   
  23. # Get the object used to communicate with the server. 
  24. $Request = [System.Net.FtpWebRequest]::Create("ftp://www.reskit.net/powershell/Greetings.Txt"
  25. $Request.Method = $Request.Method = [System.Net.WebRequestMethods+ftp]::UploadFile 
  26.  
  27. # This example assumes the FTP site uses anonymous logon. 
  28. $Request.Credentials = New-Object System.Net.NetworkCredential "anonymous","tfl@psp.co.uk" 
  29.  
  30. # Copy the contents of the file to the request stream. 
  31. $FileContents = [System.IO.File]::ReadAllBytes("C:\foo\scriptlib.zip"
  32. $Request.ContentLength = $fileContents.Length
  33. $RequestStream = $request.GetRequestStream() 
  34. $RequestStream.Write($FileContents, 0, $FileContents.Length) 
  35. $RequestStream.Close()
  36. $Response = $Request.GetResponse() 
  37. "Upload File Complete, status {0}" -f $Response.StatusDescription 
  38. $Response.Close()