Powershell basics part 11 – Interact with Windows Registry,.NET and COM objects

In this post I will talk how you can interact with registry,.NET Classes and COM Objects . We will start by talking about .NET Class and what exactly are those? .NET Framework is a framework that was developed by Microsoft and contains a large library available for many known programming languages. You can read more about .NET framework on Microsoft’s website http://msdn.microsoft.com/en-us/library/zw4w595w(v=vs.71).aspx. You can see the library of all the classes in .NET on http://msdn.microsoft.com/en-us/library/gg145045.aspx
Powershell was build also to interact with Windows registry and working with them is similar to working with files and folders. You will see that the same cmdlets used when working with files and folders are used when you interact with registry (Get-ChildItem, New-Item, Remove-Item etc.).
To locate the registry used the Get-PSDrive cmdlet:

Get-PsDrive command
Find out more about this cmdlet by typing Get-Help Get-PSDrive -full

HKEY_CURRENT_USER – Stores registry for the logged on user

HKLM or HKEY_LOCAL_MACHINE – Stores registry for the whole computer


In the picture we can see HKCU and HKLM. These are containers for Windows registry , to access them type Get-ChildItem -Path hkcu:\ or Get-ChildItem -Path hkcu:\ :
Get-Childitem Powershell

To make things easier let’s create a new registry drive:

Create new registry using Powershell
As you can see the provider is registry or Microsoft.PowerShell.Core\Registry.
Now if we change the location Set-Location hkcu1 and type dir or Get-ChildItem you will see all the registry keys contained in this drive. Now we can see a registry properties by typing the following:
Get-ItemProperty cmdlet
You can use the same cmdlets as with working with files and folders:
– To create a new registry:

New-Items -path hkcu:\Software\_soft

– To copy a registry entry to another location:
Copy-Item -path hkcu:\Software\_soft -Destination hkcu:
– To remove a registry item:
Remove-Item -path hkcu:\Software\_soft
A COM or a Component Object Model is a mechanism that provides increase powershell functionality, read more here on these links:
In order to interact with COM objects  you need to use the New-Object cmdlet. If we type Get-Help New-Object we can see that this cmdlet is used to interact with .NET Framework and COM objects to see an example of using New-Object cmdlet type Get-Help New-Object -examples:
New-Object Powershell

That’s it for this post, I don’t think there are many tutorials that will follow here under the Powershell basics tutorials, I the future we will start creating scripts in powershell or use powershell to interact with Active Directory for example. I wish all the best and stay tuned for more tutorials.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s