You can use a RegEx for this:
$out = "Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall{F1E1501C-B95C-42E0-BFD4-757DF1B961D1}"
$out -match "^.*{(?<guid>.*)}$" | Out-Null
You can then access the value like this:
$matches.Guid
-match
produces a bool that lets you know if it was successful or not. Here I discard it by sending it to Out-Null
, but you can use it to decide if you should proceeed, by, say, wrapping it in an if
:
if ($out -match "^.*{(?<guid>.*)}$")
{
# Do something
}
Note that you can get a more accurate match for the GUID using the patterns mentioned here:
RegEx for GUID