- <#
- .SYNOPSIS
- This script creates a shortcut to Notepad on the Desktop
- .DESCRIPTION
- This script creates a Wscript.shell item, then creates
- a shortcut on the desktop to Notepad.exe.
- .NOTES
- File Name : New-Shortcut.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINKS
- This post is a re-implementation of an MSDN Script
- http://msdn.microsoft.com/en-us/library/0ea7b5xe%28VS.85%29.aspx
- Posted to Powershell Scripts Blog
- HTTP://Pshscripts.blogspot.com
- .EXAMPLE
- Left as an exercise for the reader
- #>
- # create wscript object
- $WshShell = New-Object -com Wscript.Shell
- #Get Desktop location
- $Desktop = $WshShell.SpecialFolders.item("Desktop")
- # create a new shortcut
- $ShellLink = $WshShell.CreateShortcut($Desktop + "\Shortcut Script.lnk")
- $ShellLink.TargetPath = $WScript.ScriptFullName
- $ShellLink.WindowStyle = 1
- $ShellLink.Hotkey = "CTRL+SHIFT+F"
- $ShellLink.IconLocation = "notepad.exe, 0"
- $ShellLink.Description = "Shortcut Script"
- $ShellLink.WorkingDirectory = $Desktop
- #Save the link to the desktop
- $ShellLink.Save()
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Monday, 14 February 2011
New-Shortcut.ps1
Labels:
Power,
PowerShell scripts,
Wscript.Shell
Tuesday, 4 January 2011
Get-ComputerDomain.ps1
<#
.SYNOPSIS
This script uses WMI to get the name of a computer's domain then displays the name.
.DESCRIPTION
This script is a re-write of an MSDN sample, using PowerShell.
.NOTES
File Name : Get-ComputerDomain.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/aa394586%28VS.85%29.aspx/
.EXAMPLE
PSH [C:\foo]: .\Get-ComputerDomain.ps1
System Name: WIN7
Domain: cookham.net
.EXAMPLE
Psh[Cookham8]> .\Get-ComputerDomain.ps1 cookham2
System Name: COOKHAM2
Domain: cookham.net
.PARAMETER comp
The name of the computer whose domain name to be displayed. Default is localhost.
#>
# Parameter block
param (
$comp = "."
)
# Get WMI Object
$system = Get-WmiObject -class Win32_ComputerSystem -ComputerName $comp
# Display results
"System Name: {0}" -f $System.Name
"Domain: {0}" -f $System.Domain
Labels:
PowerShell scripts,
win32_computersystem,
wmi
Friday, 31 December 2010
Count-GDDuplicate.ps1
- <#
- .SYNOPSIS
- Finds duplicates in the GD archive – A script
- for New Year’s eve!
- .DESCRIPTION
- .NOTES
- File Name : Count-GDDuplicate.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2
- .LINK
- http://pshscripts.blogspot.com/2010/12/count-gdduplicateps1.html
- .EXAMPLE
- Psh[Cookham8]>C:\foo\Count-GdDuplicate.ps1
- Count-GDDuplicate.ps1 - v 1.0.1
- 99 shows have duplicates
- 109 shows are duplicates of others
- #>
- ###
- # Start of Script
- ##
- # Constants:
- # $GDDiskRoot - where to find shows
- # $DeadShowBase - folder at top of gd shows
- $GDDiskRoot = "M:"
- $DeadShowBase = $GDDiskRoot + "\gd"
- # Announce Ourselves
- "DuplicateCount.ps1 - v 0.0.1"
- "+---------------------------------+"
- "! Find Duplicate Shows : $DeadShowBase !"
- "+---------------------------------+"
- ""
- # Get start time
- $starttime = Get-Date
- set-strictmode -off
- # Get the Dead shows
- $Dir = ls $DeadShowBase | where {$_.psiscontainer}
- $DeadShows = $Dir.count
- if ($DeadSHows -le 0) {"no shows found - check constants"; return}
- # So here look for duplicates.
- $shows =@{}
- $j = 0
- foreach ($show in $dir){
- $j++
- $showdate = $show.name.substring(0,10)
- if ($shows.$showdate) {
- $shows.$showdate++
- }
- else {
- $shows += @{$showdate=1}
- }
- }
- $shows = $shows.getenumerator() | Sort name
- $totaldups = 0
- $totaldupshows = 0
- foreach ($show in $shows){
- if ($show.value -gt 1) {
- # "{1} copies of: {0}" -f $show.name, $show.value
- $totaldups++
- $totaldupshows += $show.value - 1 # anything after the 1st is a dup
- }
- }
- # Display Summary
- "{0} shows have duplicates" -f $totaldups
- "{0} shows are duplicates of others" -f $totaldupshows
Technorati Tags: Grateful Dead
Thursday, 23 December 2010
Set-IseThemeVim.ps1
- <#
- .SYNOPSIS
- This script sets an ISE Theme to similar to the old VIM editor.
- .DESCRIPTION
- This script sets the key values in $PsIse.Options to values consistent
- with the VIM editor, beloved by many, particularly on the Powershell
- product team. This script is based on Davis Mohundro's blog post
- (http://bit.ly/iib5IM), updated for RTM of PowerShell V2.0. See also
- .NOTES
- File Name : Set-ISEThemeVIM.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0 (ISE only)
- .LINK
- This script posted to:
- http://pshscriptsbog.blogspot.com
- http://bit.ly/iaA2iX
- .EXAMPLE
- This script when run resets colours on key panes, including
- colourising tokens in the script pane. Try it and see it...
- #>
- # PowerShell ISE version of the VIM blackboard theme at
- # http://www.vim.org/scripts/script.php?script_id=2280
- # Set font name and size
- $psISE.Options.FontName = 'Courier New'
- $psISE.Options.FontSize = 16
- # Set colours for output pane
- $psISE.Options.OutputPaneBackgroundColor = '#FF000000'
- $psISE.Options.OutputPaneTextBackgroundColor = '#FF000000'
- $psISE.Options.OutputPaneForegroundColor = '#FFFFFFFF'
- # Set colours for command pane
- $psISE.Options.CommandPaneBackgroundColor = '#FF000000'
- # Set colours for script pane
- $psise.options.ScriptPaneBackgroundColor ='#FF000000'
- # Set colours for tokens in Script Pane
- $psISE.Options.TokenColors['Command'] = '#FFFFFF60'
- $psISE.Options.TokenColors['Unknown'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['Member'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['Position'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['GroupEnd'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['GroupStart'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['LineContinuation'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['NewLine'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['StatementSeparator'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['Comment'] = '#FFAEAEAE'
- $psISE.Options.TokenColors['String'] = '#FF00D42D'
- $psISE.Options.TokenColors['Keyword'] = '#FFFFDE00'
- $psISE.Options.TokenColors['Attribute'] = '#FF84A7C1'
- $psISE.Options.TokenColors['Type'] = '#FF84A7C1'
- $psISE.Options.TokenColors['Variable'] = '#FF00D42D'
- $psISE.Options.TokenColors['CommandParameter'] = '#FFFFDE00'
- $psISE.Options.TokenColors['CommandArgument'] = '#FFFFFFFF'
- $psISE.Options.TokenColors['Number'] = '#FF98FE1E'
Labels:
ISE,
Powershell ISE,
PowerShell V2
Set-ISEThemeDefault.ps1
- <#
- .SYNOPSIS
- This script resets the ISE to default ‘theme’.
- .DESCRIPTION
- This script sets the key values in $PsIse.Options to their default
- options in $Psise.Options.DefaultOptions. This script is useful if you
- are playing with ISE options and don't quite get it right - just run this
- script to set things back to default.
- .NOTES
- File Name : Set-ISEThemeDefault.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0 (ISE only)
- .LINK
- This script posted to:
- http://bit.ly/gJpu2W
- .EXAMPLE
- This script when run just resets the theme to the default. To view, run from
- the ISE after changing options!
- #>
- # Set Basic options
- $psise.options.SelectedScriptPaneState = $psise.options.DefaultOptions.SelectedScriptPaneState
- $psise.options.ShowToolBar = $psise.options.DefaultOptions.ShowToolBar
- $psise.options.FontSize = $psise.options.DefaultOptions.FontSize
- $psise.options.Fontname = $psise.options.DefaultOptions.Fontname
- # set colouring
- $psise.options.ErrorForegroundColor = $psise.options.DefaultOptions.ErrorForegroundColor
- $psise.options.ErrorBackgroundColor = $psise.options.DefaultOptions.ErrorBackgroundColor
- $psise.options.WarningForegroundColor = $psise.options.DefaultOptions.WarningForegroundColor
- $psise.options.WarningBackgroundColor = $psise.options.DefaultOptions.WarningBackgroundColor
- $psise.options.VerboseForegroundColor = $psise.options.DefaultOptions.VerboseForegroundColor
- $psise.options.VerboseBackgroundColor = $psise.options.DefaultOptions.VerboseBackgroundColor
- $psise.options.DebugBackgroundColor = $psise.options.DefaultOptions.DebugBackgroundColor
- $psise.options.DebugForegroundColor = $psise.options.DefaultOptions.DebugForegroundColor
- $psise.options.OutputPaneBackgroundColor = $psise.options.DefaultOptions.OutputPaneBackgroundColor
- $psise.options.OutputPaneTextBackgroundColor = $psise.options.DefaultOptions.OutputPaneTextBackgroundColor
- $psise.options.OutputPaneForegroundColor = $psise.options.DefaultOptions.OutPutPaneForegroundColor
- $psise.options.CommandPaneBackgroundColor = $psise.options.DefaultOptions.CommandPaneBackgroundColor
- $psise.options.ScriptPaneBackgroundColor = $psise.options.DefaultOptions.ScriptPaneBackgroundColor
- $psise.options.ScriptPaneForegroundColor = $psise.options.DefaultOptions.ScriptPaneForegroundColor
- # More options
- $psise.options.ShowWarningForDuplicateFiles = $psise.options.DefaultOptions.ShowWarningForDuplicateFiles
- $psise.options.ShowWarningBeforeSavingOnRun = $psise.options.DefaultOptions.ShowWarningBeforeSavingOnRun
- $psise.options.UseLocalHelp = $psise.options.DefaultOpitons.UseLocalHelp
- $psise.options.CommandPaneUp = $psise.options.DefaultOptions.CommandPaneUp
- # Reset Tokens Colors
- $psISE.Options.TokenColors['Attribute'] = $psISE.Options.DefaultOptions.TokenColors['Attribute']
- $psISE.Options.TokenColors['Command'] = $psISE.Options.DefaultOptions.TokenColors['Command']
- $psISE.Options.TokenColors['CommandArgument'] = $psISE.Options.DefaultOPtions.TokenColors['CommandArgument']
- $psISE.Options.TokenColors['CommandParameter'] = $psISE.Options.DefaultOptions.TokenColors['CommandParameter']
- $psISE.Options.TokenColors['Comment'] = $psISE.Options.DefaultOptions.TokenColors['Comment']
- $psISE.Options.TokenColors['GroupEnd'] = $psISE.Options.DefaultOptions.TokenColors['GroupEnd']
- $psISE.Options.TokenColors['GroupStart'] = $psISE.Options.DefaultOptions.TokenColors['GroupStart']
- $psISE.Options.TokenColors['Keyword'] = $psISE.Options.DefaultOptions.TokenColors['Keyword']
- $psISE.Options.TokenColors['LineContinuation'] = $psISE.Options.DefaultOptions.TokenColors['LineContinuation']
- $psISE.Options.TokenColors['LoopLabel'] = $psISE.Options.DefaultOptions.TokenColors['LoopLabel']
- $psISE.Options.TokenColors['Member'] = $psISE.Options.DefaultOptions.TokenColors['Member']
- $psISE.Options.TokenColors['NewLine'] = $psISE.Options.DefaultOptions.TokenColors['NewLine']
- $psISE.Options.TokenColors['Number'] = $psISE.Options.DefaultOPtions.TokenColors['Number']
- $psISE.Options.TokenColors['Position'] = $psISE.Options.DefaultOptions.TokenColors['Position']
- $psISE.Options.TokenColors['StatementSeparator'] = $psISE.Options.DefaultOptions.TokenColors['StatementSeparator']
- $psISE.Options.TokenColors['String'] = $psISE.Options.DefaultOptions.TokenColors['String']
- $psISE.Options.TokenColors['Type'] = $psISE.Options.DefaultOptions.TokenColors['Type']
- $psISE.Options.TokenColors['Unknown'] = $psISE.Options.DefaultOptions.TokenColors['Unknown']
- $psISE.Options.TokenColors['Variable'] = $psISE.Options.DefaultOptions.TokenColors['Variable']
- # Done
Labels:
ISE,
Powershell ISE,
PowerShell V2
Thursday, 7 October 2010
Get-WMINameSpace.ps1
- <#
- .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"}
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)