PowerShell for Windows Admins

Jun 28 2010   3:21PM GMT

Adding a Registry value

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

6  Comments 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.
  • Adding non-string registry values - PowerShell for Windows Admins
    [...] http://itknowledgeexchange.techtarget.com/powershell/adding-a-registry-value/ [...]
    0 pointsBadges:
    report
  • warleito
    Hi, 
    I need to create a new path key like HKLM\SOFTWARE\NEWKEY

    :)
    0 pointsBadges:
    report
  • Richard Siddaway
    See this post for answer to your question http://itknowledgeexchange.techtarget.com/powershell/creating-registry-key/
    6,605 pointsBadges:
    report
  • NeoisTaken
    $reg = [wmiclass]‘\\.\root\default:StdRegprov’
    $key = "Software\Microsoft\Windows Photo Viewer\Slideshow\Screensaver" 
    $value = "Speed"

    -------------
    Return Value
    -----------------
    __GENUS          : 2
    __CLASS          : __PARAMETERS
    __SUPERCLASS     : 
    __DYNASTY        : __PARAMETERS
    __RELPATH        : 
    __PROPERTY_COUNT : 1
    __DERIVATION     : {}
    __SERVER         : 
    __NAMESPACE      : 
    __PATH           : 
    ReturnValue      : 6
    PSComputerName   : 




    where do I lookup the return code 6?
    10 pointsBadges:
    report
  • Richard Siddaway
    try MSDN
    6,605 pointsBadges:
    report
  • NeoisTaken
    Brilliant, thank you for a basic answer. I found this site on page 3 of google. I would expect you to realise if anyone posts here, it is after several hours of research. 

    I have already found my solution. Never did find what return code 6 was.
    10 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:

Share this item with your network: