Powershell compare two variables
Hi,
I am comparing two equal variables but I am always getting "FALSE" when I do a proof:
$vCondition1 = Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"{E95BCA9A-F9ED-48C7-AFB3-4053A0F1E02C}"
$vCondition2 = Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"{E95BCA9A-F9ED-48C7-AFB3-4053A0F1E02C}"
($vCondition1 -eq $vCondition2)
September 8th, 2015 9:26am
Those are objects. Test on the properties.
September 8th, 2015 9:49am
Like mike said something like this
$value1 = Get-ItemProperty 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{012D26C3-E12A-3BDA-8ECE-DF14E721A507}'
$value2 = Get-ItemProperty 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{012D26C3-E12A-3BDA-8ECE-DF14E721A507}'
if($value1.PSChildName -eq $value2.PSChildName)
{
"Yes - The ID's are same!"
}
else
{
"Nope - Match failed!"
}
In your code try like this
$vCondition1 = Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"{E95BCA9A-F9ED-48C7-AFB3-4053A0F1E02C}"
PS C:\> $vCondition1.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False PSCustomObject System.Object
September 8th, 2015 9:52am
Hi your script is working, thanks for that.
But if I edit it for my script it does not work anymore:
$value1 = Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.Publisher -like "Lattice"+"*"}
$value2 = Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.Publisher -like "Lattice"+"*"}
if($value1.PSChildName -eq $value2.PSChildName)
{
"Yes - The ID's are same!"
}
else
{
"Nope - Match failed!"
}
September 8th, 2015 10:35am
What is the actual point of this exercise?
Side note - why are you doing this: "Lattice"+"*"? Just do this 'Lattice*'
September 8th, 2015 10:42am
at the end i have to proof if a registry key exits or not. I will do this in a Loop. Once the key is not theit any more, i have to end the Setup process.
September 8th, 2015 10:45am
What setup process? Why do you need to do something in a loop?
Remember, we can't see your screen.
Tell what you want to do, not
how you think you need to do it.
September 8th, 2015 10:46am
at the end i have to proof if a registry key exits or not. I will do this in a Loop. Once the key is not theit any more, i have to end the Setup process.
So you're trying to do some sort of installation kludge?
Do yourself a favor and stop right now. Fix the installation issue instead of doing whatever you're trying to do.
September 8th, 2015 10:52am
Ok I try to explain.
I am having a Software installed (Name XVL Player / Publisher Lattice) in a lot of different Versions.
On some Computers the software is installed a view times in different Versions.
The Problem is that the Software does not have a silent uninstall Option.
I grab the uninstall string and run it. once the Setup stands at the last window i have to Close that window.
to be sure that the uninstallation was successful i check if the registry still Exits.
if not, i stop the Setup process.
September 8th, 2015 10:52am
To check a registry key use "Test-Path hklm:\Software\....\keyname"
It is that easy.
September 8th, 2015 11:29am