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

Registry-A

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

Registry-0

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.

Registry-1

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

Registry-2

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.

New-ItemProperty -Path 'hklm:\software\CompanyName\' -Name "Department" -Value "I.T"

Registry-3

Let’s check ….. Key is created . . . .

Registry-4

okies..

what if you need to change the value of the key?, you can do it easily using Set-ItemProperty cmdlet.

Now Lets change the department name from “I.T.” to “Accounts”

set-ItemProperty -Path 'hklm:\software\CompanyName\' -Name "Department" -Value "Accounts"

 Registry-5

Let’ See…….yes Department name is changes from “I.T.” to “Accounts”

Registry-6

 

I hope this post will save someone time :) ..

Thanks

Aman Dhally

www.amandhally.net/blog

4 comments:

  1. Thanks for informing about PowerShell. We are providing also updates with update software latest

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. I learned your posting! its really informative and helpful.
    acdsee pro 8 keygen

    ReplyDelete