- <#
- .SYNOPSIS
- This script sets a registry binary value
- using WMI.
- .DESCRIPTION
- This script uses WMI to set a binary
- registry Value.
- This is a re-write of a VB Sample Script.
- .NOTES
- File Name : Set-WmiRegistryBinaryValue.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]>New-WmiRegistryBinaryValue.ps1
- Value created
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $ValueName = "Example Binary Value"
- $Values = @(0x54, 0x46, 0x4C)
- $Key = "SOFTWARE\NewKey"
- # Create Value entry
- $results = $reg.SetBinaryValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Values)
- If ($results.Returnvalue -eq 0) {"Value Set"}
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Sunday, 11 September 2011
Set-WmiRegistryBinaryValue
Saturday, 10 September 2011
New-WmiRegistryValue.ps1
- <#
- .SYNOPSIS
- This script creates a new registry Value using WMI.
- .DESCRIPTION
- This script uses WMI to get create a new registry Value.
- This is a re-write of a VB Sample Script
- .NOTES
- File Name : New-RegistryKey.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]>New-WmiRegistryValue.ps1
- Value created
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $ValueName = "Example_Expanded_String_Value"
- $Value = "%PATHEXT%"
- $Key = "SOFTWARE\NewKey"
- # Create Value entry
- $results = $reg.SetExpandedStringValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Value)
- If ($results.Returnvalue -eq 0) {"Value created"}
Labels:
SetExpandedStringValue,
StdRegProv,
wmi
Set-WmiMultiStringValue.ps1
- <#
- .SYNOPSIS
- This script sets a registry binary value
- using WMI.
- .DESCRIPTION
- This script uses WMI to set a multistring
- registry Value.
- This is a re-write of a VB Sample Script.
- .NOTES
- File Name : Set-WmiRegistryMultiStringValue.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]>Set-MultiStringValue.ps1
- Value created
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $Key = "SOFTWARE\NewKey"
- $ValueName = "Example MultiString Value"
- $Values = @("Thomas", "Susan", "Rebecca")
- $Key = "SOFTWARE\NewKey"
- # Create Value entry
- $results = $reg.SetMultiStringValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Values)
- If ($results.Returnvalue -eq 0) {"Value Set"}
Friday, 9 September 2011
New-WmiRegistryKey.ps1
- <#
- .SYNOPSIS
- This script creates a new registry key using WMI.
- .DESCRIPTION
- This script uses WMI to get create a new registry key.
- This is a re-write of a VB Sample Script
- .NOTES
- File Name : New-RegistryKey.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]>New-WMIRegistryKey.ps1
- Key created
- #>
- # Define Constants
- $HKEY_Local_Machine =2147483650
- $computer ='.'
- # Get Class to call static methods on
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
- # Define key to create
- $Key = "SOFTWARE\NewKey"
- # Create key and display reslts
- $results = $reg.CreateKey($HKEY_LOCAL_MACHINE, $Key)
- If ($results.Returnvalue -eq 0) {"Key created"}
Thursday, 8 September 2011
Get-WmiRegDword.ps1
- <#
- .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
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
Subscribe to:
Posts (Atom)