PowerShell for Windows Admins

Jun 27 2010   4:33AM GMT

Adding a Registry Key

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

We seen how to read the registry – now its time to look at writing to the registry.

At this point I have to supply the usual warnings about altering the registry – it can damage your machine if things go wrong. In addition registry errors have been blamed for the extinction of the dinosaurs, the big bang and the energy death of the universe – you have been warned  🙂

We’ll start by creating a new key in a safe(-ish) place.  This has the advantage of not altering anything.



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

$key = "SOFTWARE\ITKE PSAdmins"
$reg.CreateKey($HKLM, $key)

We need to define the constant for the HKLM hive, define the machine we are interested in – this could be a parameter to our script/function.

Create the WMI object for the registry, define the key to be created and then use the CreateKey method to actually perform the creation.  Use regedit to confirm the result or use the PowerShell registry provider

Get-ChildItem -Path hklm:\software\itk*

 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.

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: