PowerShell for Windows Admins

Jun 28 2010   3:21PM GMT

Adding a Registry value



Posted by: Richard Siddaway
Tags:
PowerShell v2
Registry
WMI

Last time we saw how to add a registry key – this we add a string value to that key

001
002
003
004
005
006
007
008
009
010
$HKLM = 2147483650 #HKEY_LOCAL_MACHINE

$computer = "."  #local machine
$reg = [wmiclass]"\\$computer\root\default:StdRegprov"

$key = "SOFTWARE\ITKE PSAdmins"
$name = "String Entry"
$value = "This is a string"

$reg.SetStringValue($HKLM, $key, $name, $value)

Very similar to last time except after defining the key we define a subkey and its value.  In this case both strings.

The SetStringValue methods is used to create the value. It can also be used to modify the value

 

001
002
003
004
005
006
007
008
009
010
$HKLM = 2147483650 #HKEY_LOCAL_MACHINE

$computer = "."  #local machine
$reg = [wmiclass]"\\$computer\root\default:StdRegprov"

$key = "SOFTWARE\ITKE PSAdmins"
$name = "String Entry"
$value = "This is a string 2"

$reg.SetStringValue($HKLM, $key, $name, $value)

The set methods will alter the value if it present or create it if its not.

Next time we’ll look at some of the other methods and types of data. There is one method for each data type as when we were reading

1  Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Richard Siddaway
    [...] http://itknowledgeexchange.techtarget.com/powershell/adding-a-registry-value/ [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: