Working with Powershell and the Registry


This article explain how to test whether parts of the registry structure exist for a user.

The following will test if a key exists in the registry:
Test-path “HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles”

This will return either True or False

You can also do this to see if a property exists in the key as below:
Test-path “HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\DefaultProfile”

Using an IF statement it allows us to run a program off the back of the result, as seen below:

$RegPath = Test-path “HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\DefaultProfile”
#$OutlookPath = “C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE /importprf \\fileservername\ExchangeOutlook_PRF\exchange2007.prf
If ($RegPath -eq $True)
{Write-host “No Outlook Profile”}
else
{start-process -filepath “C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE”}

No comments yet... Be the first to leave a reply!

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 )

Connecting to %s

%d bloggers like this: