PowerShell for Windows Admins

Jul 4 2010   10:22AM GMT

Adding non-string registry values



Posted by: Richard Siddaway
Tags:
PowerShell v2
Registry

We recently looked at adding a string string registry value to the key we had created.

http://itknowledgeexchange.techtarget.com/powershell/adding-a-registry-value/

In this post we’ll extend this to other types

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
$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)

$name = "Expanded String Entry"
$value = "%temp%"
$reg.SetExpandedStringValue($HKLM, $key, $name, $value)

$name = "Dword Entry"
$value = 101
$reg.SetDWORDValue($HKLM, $key, $name, $value)

$name = "Multi-string Entry"
$value = "A","B","C","D"
$reg.SetMultiStringValue($HKLM, $key, $name, $value)

The pattern established for writing a string value is used across the other values.  An expanded string picks up it value from an environmental variable – so if we want to access the temp folder we can use %temp% and find that folder on all machines.

A multi-string value takes a list of strings. if you change this it will overwrite so we need to read the current value, append new data and then write it back – next time

 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

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: