- <#
- .SYNOPSIS
- This script displays all the WMI namespaces within a Windows system
- .DESCRIPTION
- This script uses Get-WMIObject to retrieve the names of all the namespaces
- within a system.
- .NOTES
- File Name : Get-WMINameSpace.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/10/get-wminamespaceps1.html
- .EXAMPLE
- PSH [C:\foo]: .\Get-WMINameSpace.ps1
- 37 Namespaces on: Cookham8
- Namespace
- ---------
- ROOT
- ROOT\aspnet
- ROOT\CIMV2
- ROOT\CIMV2\Security
- ROOT\CIMV2\Security\MicrosoftTpm
- ... {Remainder of list snipped to save space on this page}
- #>
- # Set computer name
- $comp = "."
- # Get the name spaces on the local computer, and the local computer name
- $Namespace = get-wmiobject __namespace -namespace 'root' -list -recurse -computer $comp
- $hostname = hostname
- # Display number of and names of the namespaces
- "{0} Namespaces on: {1}" -f $namespace.count, $hostname
- $NameSpace| sort __namespace | Format-Table @{Expression = "__Namespace"; Label = "Namespace"}
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Thursday, 7 October 2010
Get-WMINameSpace.ps1
Labels:
namespace,
powershell,
PowerShell scripts,
PowerShell V2,
wmi
Wednesday, 6 October 2010
Get-LoopBack.ps1
- <#
- .SYNOPSIS
- This script checks whether a parameter is a Loopback Address
- .DESCRIPTION
- This script checks to see if the passsed string is an IPV4
- or an IPv6 loopback address and if so, displays details.
- .NOTES
- File Name : Get-LoopBack.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.net.ipaddress.isloopback.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-LoopBack.ps1
- Your input address: \127.0.0.1\ is an IPv4 loopback address whose internal format is: 127.0.0.1.
- .EXAMPLE
- PSH [C:\foo]: .\Get-LoopBack.ps1 ::1
- Your input address: \::1\ is an IPv6 loopback address whose internal format is: ::1.
- .EXAMPLE
- PSH [C:\foo]: .\Get-LoopBack.ps1 131.107.2.200
- Your input address: \131.107.2.200\ is not a loopback address.
- .PARAM
- $IPAddress - Address to look up to see if it's Loopback
- #>
- param (
- [String] $IpAddress = "127.0.0.1"
- )
- # Setup Default answer!
- $loopBack=" is not a loopback address.";
- # Perform syntax check by parsing the address string entered by the user.
- $Address = [System.Net.IPAddress]::Parse($IpAddress);
- # Perform semantic check by verifying that the address is a valid IPv4
- # or IPv6 loopback address.
- if([System.Net.IPAddress]::IsLoopback($Address) -and ($address.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetworkV6) ) {
- $loopBack = " is an IPv6 loopback address " +
- "whose internal format is: " + $Address.ToString() + ".";
- }
Labels:
powershell,
PowerShell scripts,
system.net.ipaddress
Tuesday, 5 October 2010
Get-HostByName.ps1
- <#
- .SYNOPSIS
- This script gets and displays basic DNS Information about a host.
- .DESCRIPTION
- This script just gets and displays host details returnd by GetHostByName.
- .NOTES
- File Name : Get-ByName.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted tot:
- http://msdn.microsoft.com/en-us/library/system.net.dns.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-HostByName.ps1
- HostName : contoso.com
- Aliases : {www.contoso.com}
- AddressList : {207.46.197.32, 207.46.232.182}
- #>
- $hostInfo = [system.net.Dns]::GetHostByName("www.contoso.com");
- $hostinfo | fl * -force
Labels:
powershell,
PowerShell scripts,
System.Net.Dns
Monday, 4 October 2010
Remove-FtpFile.ps1
- <#
- .SYNOPSIS
- This script deletes a file from an FTP Server
- .DESCRIPTION
- This script is a rewrite of an MSDN Sample
- .NOTES
- File Name : Remove-FtpFile.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted tot:
- http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Remove-FtpFile.ps1
- Delete status: 250 DELE command successful.
- #>
- $ServerUri = New-Object System.Uri "ftp://www.reskit.net/powershell/foo.txt"
- # The serverUri parameter should use the ftp:// scheme.
- # It contains the name of the server file that is to be deleted.
- # Example: ftp://contoso.com/someFile.txt.
- if ($ServerUri.Scheme -ne [system.Uri]::UriSchemeFtp) {
- " Bad URI"; return
- }
- # Get the object used to communicate with the server.
- $request = [system.Net.FtpWebRequest]::Create($serverUri)
- $request.Method = [System.Net.WebRequestMethods+ftp]::Deletefile
- $Request.Credentials = New-Object System.Net.NetworkCredential "anonymous","tfl@psp.co.uk"
- $response = $request.GetResponse()
- "Delete status: {0}" -f $response.StatusDescription
- $response.Close();
Sunday, 3 October 2010
Copy-FileToFtp.ps1
- <#
- .SYNOPSIS
- This script Uploads a text file to an FTP Server using PowerShell.
- .DESCRIPTION
- This script first creates an FTP 'web' request to upload a file. Then the
- source file is read from disk and written up to the FTP Server. A response
- is then displayed. This is a rewrite of an MSDN Sample.
- .NOTES
- File Name : Copy-FileToFtp.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/10/copy-filetoftpps1.html
- MSDN sample posted tot:
- http://msdn.microsoft.com/en-us/library/ms229715.aspx
- .EXAMPLE
- PSH [C:\foo]: .Copy-FileToFtp.ps1
- Upload File Complete, status 226
- 226 Transfer complete.
- #>
- # Get the object used to communicate with the server.
- $Request = [System.Net.FtpWebRequest]::Create("ftp://www.reskit.net/powershell/Greetings.Txt")
- $Request.Method = $Request.Method = [System.Net.WebRequestMethods+ftp]::UploadFile
- # This example assumes the FTP site uses anonymous logon.
- $Request.Credentials = New-Object System.Net.NetworkCredential "anonymous","tfl@psp.co.uk"
- # Copy the contents of the file to the request stream.
- $FileContents = [System.IO.File]::ReadAllBytes("C:\foo\scriptlib.zip")
- $Request.ContentLength = $fileContents.Length
- $RequestStream = $request.GetRequestStream()
- $RequestStream.Write($FileContents, 0, $FileContents.Length)
- $RequestStream.Close()
- $Response = $Request.GetResponse()
- "Upload File Complete, status {0}" -f $Response.StatusDescription
- $Response.Close()
Subscribe to:
Posts (Atom)