You’ve only asked ChatGPT? What about google or bing? I find it hard to believe you’re not able to find ANY helpful information. I’m curious what question(s) you have asked it that gave you nothing even close.
ME: extract guid from uninstall string using powershell
ChatGPT:
You can extract the GUID from an uninstall string using PowerShell by using regular expressions. The uninstall string typically contains the path to the uninstaller executable along with the GUID, which is enclosed in curly braces {}. Here's a PowerShell script to extract the GUID:
powershell
Copy code
# Define the uninstall string
$uninstallString = 'C:\Program Files\Example\Uninstall.exe /GUID={12345678-1234-5678-1234-567812345678}'
# Use regular expressions to extract the GUID
$match = [regex]::Match($uninstallString, '\{[A-F0-9-]+\}')
# Check if a match was found
if ($match.Success) {
# Extract the GUID from the match
$guid = $match.Value
Write-Host "Extracted GUID: $guid"
} else {
Write-Host "No GUID found in the uninstall string."
}
In this script:
We define the uninstall string ($uninstallString) as an example.
We use the [regex]::Match method to search for a pattern within the uninstall string. The pattern '\{[A-F0-9-]+\}' looks for a sequence of characters enclosed in curly braces {} consisting of uppercase letters A-F, digits 0-9, and hyphens.
If a match is found (i.e., if $match.Success is true), we extract the matched GUID from $match.Value and display it.
You can replace the $uninstallString variable with the actual uninstall string you want to extract the GUID from.
Why don’t you share your code? So we might be able to tell what’s wrong with it. And what’s the actual purpose of your script?
And just to have it mentioned at least once: Not all uninstall strings you’ll find in the registry actually trigger a de-installation of an app. Some only launch the setup interactivly.
Do you actually read your own posts when you posted them?
Please … when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Did you read my response? It literally showed you a way to get exactly what you want.
# Define the uninstall string
$uninstallString = 'C:\Program Files\Example\Uninstall.exe /GUID={12345678-1234-5678-1234-567812345678}'
# Use regular expressions to extract the GUID
$match = [regex]::Match($uninstallString, '\{[A-F0-9-]+\}')
# Check if a match was found
if ($match.Success) {
# Extract the GUID from the match
$guid = $match.Value
Write-Host "Extracted GUID: $guid"
} else {
Write-Host "No GUID found in the uninstall string."
}