I'd like to make Powershell script which get specific string from the line. This string might be on different lines. So text file looks like this - 1st file -
[Bootstrap]
buildid=400m3(Build:9702)
ProductBuildid=9702
ProductCode={55E61709-D7D4-43C0-B45D-BFAF5C09A02D}
UpgradeCode={7C35B9AB-2CE3-4C18-BE7C-5B97EA089EB3}
2nd file -
[Bootstrap]
ProductCode={2BB8FBB4-CFF9-434E-AA0A-40F5379C1602}
I need to get MSI code after ProductCode=
$openofficeSetup = "C:\Program Files (x86)\openoffice*\program\setup.ini"
if (Test-Path $openofficeSetup)
{
$openofficeMSI = Select-String "ProductCode=*" $openofficeSetup
$openofficeMSI = $openofficeMSI -Replace "*ProductCode=", ""
msiexec.exe /x $openofficeMSI /qn
Line 5 with -Replace is wrong. i have no idea how to remove everything before.
PS N:\> echo $openofficeMSI
C:\Program Files (x86)\OpenOffice 4\program\setup.ini:4:ProductCode={55E61709-D7D4-43C0-B45D-BFAF5C09A02D}
How can I get rid of everything but MSI code?
Offtopic: Other way would searching for MSI code in registry HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\ but using setup.ini looks easier.