Powershell if exist

Hi can some one help with this.
need a script to check the registry and if a value exists carry on and run rest of script if reg entry doesnt exist error out

so sccm wont run if regentry isnt present

this is an edit of something that might work but it doesnt :-)

if ((Test-Path "hklm:\Software\mch\$Manufacturer\$Product\$Ver") -eq $false) 
	$reg=Get-Itemproperty $RegPath
	if ($reg.Media_Reference -eq $installmediaid) {wegotaproblem "$Product is not installed"}

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

You can stop a script with "Break", or you can throw an error (Throw "Because of Some Error").

In the snippet above, you're testing a path to see if it exists. Then if it doesn't you're attempting to get a value from the path... which is a bit of an unusual choice...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mhamerAuthor Commented:
im editing an entry from another script that checks version number and does the opposite it exits if already installed
Chris DentPowerShell DeveloperCommented:

It was only really this bit that's troubling :)

(Test-Path TheRegKey) -eq $false

Because it's followed with "Get-Item TheRegKey" which only runs if the key doesn't exist which will break. A bit backwards you see.

mhamerAuthor Commented:
the code i posted was relying on other stuff elseware in script  so it makes sense when you see the whole, but just breaking was fine for what i was needing  thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.