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.
New-ItemProperty -Path 'hklm:\software\CompanyName\' -Name "Department" -Value "I.T"
Let’s check ….. Key is created . . . .
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"
Let’ See…….yes Department name is changes from “I.T.” to “Accounts”
I hope this post will save someone time :) ..
Thanks
Aman Dhally
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.