- <#
- .SYNOPSIS
- This script gets a registry value using WMI.
- .DESCRIPTION
- This script uses WMI to get then display a resistry value, using
- the SteRegProv class and the GetDWORDValue static method.
- This is a re-write of a VB Sample Script
- .NOTES
- File Name : Get-WMIRegDword.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/aa394600%28VS.85%29.aspx
- .EXAMPLE
- Psh[C:\foo]>Get-WmiRegDword.ps1
- Current History Buffer Size: 50
- #>
- # Define Constants
- $HKEY_CURRENT_USER =2147483649
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- #defind key/value to get
- $Key = "Console"
- $Value = "HistoryBufferSize"
- # Get Value of buffer and display
- $results = $reg.GetDWORDValue($HKEY_CURRENT_USER, $Key, $value)
- "Current History Buffer Size: {0}" -f $results.uValue
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Thursday, 8 September 2011
Get-WmiRegDword.ps1
Sunday, 14 August 2011
Show-MajorPart.ps1
- <#
- .SYNOPSIS
- This script shows the Major part of the version number
- of file version object.
- .DESCRIPTION
- This script is a re-implementation of an MSDN Sample script
- that uses System.Diagnostics.FileVersionInfo to get
- the major part of the version number of the file.
- .NOTES
- File Name : Show-MajorPart.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2011/08/show-majorpartps1.html
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.filemajorpart.aspx
- .EXAMPLE
- Psh> .\Show-MajorPart.ps1
- File Major Part for C:\Windows\system32\Notepad.exe is: 6
- #>
- # Set filename
- $File = [System.Environment]::SystemDirectory + "\Notepad.exe"
- #Get Version information for this file
- $myFileVersionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($File)
- # Print the Build details name
- "File Major Part for {0} is: {1}" -f $file,$myFileVersionInfo.FileMajorPart
Thursday, 14 July 2011
Show-MinorPart.ps1
- <#
- .SYNOPSIS
- This script shows the Minor part of the version number
- of file version object.
- .DESCRIPTION
- This script is a re-implementation of an MSDN Sample script
- that uses System.Diagnostics.FileVersionInfo to get
- the mainor part of the version number of the file.
- .NOTES
- File Name : Show-MinorPart.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://http://pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.FileMinorpart.aspx
- .EXAMPLE
- Psh> .\Show-MinorPart.ps1
- File Major Part for C:\Windows\system32\Notepad.exe is: 0
- #>
- # Set filename
- $File = [System.Environment]::SystemDirectory + "\Notepad.exe"
- #Get Version information for this file
- $myFileVersionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($File)
- # Print the Build details name
- "File Minor Part for {0} is: {1}" -f $file,$myFileVersionInfo.FileMinorPart
Sunday, 19 June 2011
Get-ParsedInteger.ps1
- <#
- .SYNOPSIS
- This script parses several strings into integers, where possible.
- .DESCRIPTION
- This script uses the TryParse method on [Int32] to attempt
- to parse a string into a number and writes the results. This script
- is a recoded MSDN sample using PowerShell
- .NOTES
- File Name : Get-ParsedInt32.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/f02979c7.aspx
- .EXAMPLE
- Psh[C:\foo]> .\get-parsedinteger.ps1
- Attempted conversion of '' failed.
- Converted '160519' to 160519.
- Attempted conversion of '9432.0' failed.
- Attempted conversion of '16,667' failed.
- Converted ' -322 ' to -322.
- Converted '+4302' to 4302.
- Attempted conversion of '(100);' failed.
- Attempted conversion of '01FA' failed.
- #>
- # Define function to parse a string to integer
- Function TryToParse {
- # Parameter to parse into a number
- Param ([string] $value)
- # Define $number and try the parse
- [int] $number = 0
- $result = [System.Int32]::TryParse($value, [ref] $number);
- if ($result) {
- "Converted '{0}' to {1}." -f $value, $number
- }
- else {
- if ($value -eq $null) {$value = ""}
- "Attempted conversion of '{0}' failed." -f $value
- }
- }
- # Now call the function to see if the string will parse
- TryToParse($null)
- TryToParse("160519");
- TryToParse("9432.0");
- TryToParse("16,667");
- TryToParse(" -322 ");
- TryToParse("+4302");
- TryToParse("(100);");
- TryToParse("01FA");
Technorati Tags: System.Int32,TryParse()
Tuesday, 29 March 2011
New-Credential.ps1
- <#
- .SYNOPSIS
- A function to create a credential object from script.
- .DESCRIPTION
- Enables you to create a credential objects from stored details.
- .NOTES
- File Name : New-Credential.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2011/03/new-credentialps1.html
- .PARAMETER UserId
- The userid in the form of "domain\user"
- .PARAMETER Password
- The password for this user
- .EXAMPLE
- New-Credential contoso\administrator Pa$$w0rd
- #>
- function New-Credential {
- param (
- [string] $Userid,
- [string] $Pwd
- )
- # Create the credential
- $spwd = ConvertTo-SecureString -AsPlainText $pwd -Force
- $cred = New-Object System.Management.Automation.PSCredential $userid,$spwd
- # Now return it to the caller
- return $cred
- }
- # Call the function to demostrate example
- New-Credential "contoso\administrator" "Pa$$w0rd"
Labels:
credential,
powershell,
PowerShell V2,
security
Monday, 14 February 2011
New-Shortcut.ps1
- <#
- .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()
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
Subscribe to:
Posts (Atom)