Pages

Monday, November 14, 2011

How to create and change “Windows Registry Keys” using PowerShell.

Hi,

The Best thing about PowerShell is that you can manipulate “windows Registry Keys” very easily with it. How? Let me show to you.

Why we need to create a registry Hive/key manually?

Actually for lots of reason, for example if you want to install some particular software on all accounting computer automatically and then you can need write a script which check the predefined registry Keys and if it found that the in key Department is “accounts” then install it may install some accounting software on it otherwise don’t do anything.

Cmdlets used: New-Item , New-ItemProperty, Set-ItemProperty

Before running the below command make sure you run PowerShell as Administrator.

How to run PowerShell as Administrator?

to do this , Search for PowerShell { you can also access the same from Start > All Programs > Accessories > windows PowerShell > Windows PowerShell} , Right Click on it and Choose “Run as Administrator”

When you run PowerShell as Administrator you will see that the title bar of PowerShell windows shows Administrator:

Now let’s create a new Folder named “CompanyName” in “Hkey_Local_machine” and beneath Software key folder.

In PowerShell we can use Registry hives as Local drives so we can use New-item cmdlet to create a new registry hive.

new-Item -Name "CompanyName" -Path 'hklm:\SOFTWARE\' -type Directory

New-Item : used to create a new folder for file

-Name : Name of the Folder

-Path: where we want to create a new folder

-Type: Directory in our case because “CompanyName” will contain some sub registry keys.

Let’s check . . . Yes “Registry Hive” is created . .

now lets create a new Registry key in “ComanyName” names as “Department” which have some information about which on Department the laptop/desktop belong to.