- <
- .SYNOPSIS
- This script Gets and displays a registry
- binary value using WMI.
- .DESCRIPTION
- This script uses WMI to get, then display
- 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]>Get-WmiRegistryBinaryValue.ps1
- 54
- 46
- 4c
-
-
-
- $HKEY_Local_Machine =2147483650
- $computer ='.'
-
-
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
-
-
- $ValueName = "Example Binary Value"
- $Values = @(0x54, 0x46, 0x4C)
- $Key = "SOFTWARE\NewKey"
-
-
- $results = $reg.GetBinaryValue($HKEY_LOCAL_MACHINE, $Key, $ValueName)
- Foreach ($byte in $results.uvalue) {"{0}" -f $byte.tostring("x")}
W
- <
- .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
-
-
-
- $HKEY_Local_Machine =2147483650
- $computer ='.'
-
-
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
-
-
- $ValueName = "Example Binary Value"
- $Values = @(0x54, 0x46, 0x4C)
- $Key = "SOFTWARE\NewKey"
-
-
- $results = $reg.SetBinaryValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Values)
- If ($results.Returnvalue -eq 0) {"Value Set"}
- <
- .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
-
-
-
- $HKEY_Local_Machine =2147483650
- $computer ='.'
-
-
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
-
-
- $ValueName = "Example_Expanded_String_Value"
- $Value = "%PATHEXT%"
- $Key = "SOFTWARE\NewKey"
-
-
- $results = $reg.SetExpandedStringValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Value)
- If ($results.Returnvalue -eq 0) {"Value created"}
- <
- .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
-
-
-
- $HKEY_Local_Machine =2147483650
- $computer ='.'
-
-
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
-
-
- $Key = "SOFTWARE\NewKey"
- $ValueName = "Example MultiString Value"
- $Values = @("Thomas", "Susan", "Rebecca")
- $Key = "SOFTWARE\NewKey"
-
-
- $results = $reg.SetMultiStringValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Values)
- If ($results.Returnvalue -eq 0) {"Value Set"}
- <
- .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
-
-
-
- $HKEY_Local_Machine =2147483650
- $computer ='.'
-
-
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
-
-
- $Key = "SOFTWARE\NewKey"
-
-
- $results = $reg.CreateKey($HKEY_LOCAL_MACHINE, $Key)
- If ($results.Returnvalue -eq 0) {"Key created"}
- <
- .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
-
-
-
-
- $HKEY_CURRENT_USER =2147483649
- $computer ='.'
-
-
- $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv"
-
-
- $Key = "Console"
- $Value = "HistoryBufferSize"
-
-
- $results = $reg.GetDWORDValue($HKEY_CURRENT_USER, $Key, $value)
- "Current History Buffer Size: {0}" -f $results.uValue
- <
- .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
-
-
- $File = [System.Environment]::SystemDirectory + "\Notepad.exe"
-
-
- $myFileVersionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($File)
-
-
- "File Major Part for {0} is: {1}" -f $file,$myFileVersionInfo.FileMajorPart
- <
- .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
-
-
- $File = [System.Environment]::SystemDirectory + "\Notepad.exe"
-
-
- $myFileVersionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($File)
-
-
- "File Minor Part for {0} is: {1}" -f $file,$myFileVersionInfo.FileMinorPart
- <
- .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.
-
-
-
- Function TryToParse {
-
- Param ([string] $value)
-
- [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
- }
- }
-
-
- TryToParse($null)
- TryToParse("160519");
- TryToParse("9432.0");
- TryToParse("16,667");
- TryToParse(" -322 ");
- TryToParse("+4302");
- TryToParse("(100);");
- TryToParse("01FA");
- <#
- .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"