Link to home
Start Free TrialLog in
Avatar of mhamer
mhamer

asked on

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) 
{
	$RegPath="hklm:\Software\mch\$Manufacturer\$Product\$Ver"
	$reg=Get-Itemproperty $RegPath
	if ($reg.Media_Reference -eq $installmediaid) {wegotaproblem "$Product is not installed"}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mhamer
mhamer

ASKER

im editing an entry from another script that checks version number and does the opposite it exits if already installed

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.

Chris
Avatar of mhamer

ASKER

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