Hey there coders!
First time on here, and only been coding in PS for a week, so be gentle :).
I have made a rather long script that does the following:
Ask for a installed Product Name
Ask for the publisher (failsafe, will remove later)
Scan Uninstall reg keys for matches of publisher and product name using wildcards
if matches found, prompt for each match if removal is to happen
If yes, then kick of MSIEXEC for the product (I have removed this step, and replaced it with a "writehost" of the msiexec for now, while testing)
Once done, check the reg key to see if it still exists (if still there, removal failed, if gone, removal worked)
Then moves on to next product, and so forth.
All my code works as expected except for the Reg check part, it always returns as "false", but the key has not been removed as I have not performed any uninstall in testing phase, so the key still exists!
I have temporarily chucked code in to spit out the variables full path, and the value of the "test-path" to the console to see what it is doing.
Example Output:
Found: Intel(R) Wireless Bluetooth(R) : {00000010-0200-1033-84C8-B8D95FA3C8C3}
Are you sure you want to remove Intel(R) Wireless Bluetooth(R)?: y
Removing...
msiexec.exe /x {00000010-0200-1033-84C8-B8D95FA3C8C3} /qn /norestart
False
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{00000010-0200-1033-84C8-B8D95FA3C8C3}
Removed 'Intel(R) Wireless Bluetooth(R)' successfully
This is the code Snippet where this part resides:
$keys = Get-ChildItem -path $UninstKey |
Where-Object { $_.PSChildName -match '^{\w{8}-(\w{4}-){3}\w{12}}$' -and ($_.GetValue('DisplayName') -like "*$prodname*") -and ($_.GetValue('Publisher') -like "*$Vendorname*") } |
Select-Object @{n='GUID';e={$_.PSChildName}}, @{n='Vendor';e={$_.GetValue('Publisher')}}, @{n='Product'; e={$_.GetValue('DisplayName')}}, @{n='Name'; e={$_.Name}}
if ($keys.count -eq 0) {
Write-Host "Nothing found!"
Exit
} Else {
Write-Host "Products found!"
}
foreach ($key in $keys) {
Write-Host `n"Found: $($key.Product) : $($key.GUID)"
$confirmation = Read-Host "Are you sure you want to remove $($key.Product)?"
if ($confirmation -eq 'y') {
$MSIargs = @(
"/x"
"$($key.GUID)"
"/qn"
"/norestart"
)
Write-Host "Removing..."
Write-host "msiexec.exe" $MSIargs #Start-Process "msiexec.exe" -ArgumentList $MSIargs -Wait } -NoNewWindow #The Nuke Payload
Write-Host (Test-Path $key.Name)
Write-Host $key.Name
if (Test-Path $key.Name) { #$testremove
Write-Host "Failed to remove: '"$($key.Product)"'"
}
else {Write-Host "Removed" "'$($key.Product)'" "successfully"}
As you can see with the Write-Host, the value of "$key.name" is the correct registry path, but returns a "false"?
As mentioned, the rest of the script works fine without errors and everything else works as intended, I literally just need the value to read true when the registry exists.
As mentioned, I can navigate to this location in regedit without issues.
I am certain it is something super simple I have looked over and I would greatly appreciate your help on this!
Please let me know if you need any more information!