Hi all,
i have a question regarding invoking external programs in a powershell script.
Recently i had to deal with removing java. So i have written a small script which gets the Product ID and removes the broken installer with msizap.exe.
So i searched with get-wmiobject after java and tried to put it with strings together, then execute the command.
My dirty script looked like:
$mymsizap = "\\unc\path\msizap.exe"
Get-WmiObject -class win32_product | where-object { $_.Caption -like "Java*" } | foreach {
$j = $mymsizap + " T " + $_.identifyingnumber
iex $j
}
I invoked it in a Administrative Command Promt with c:\path\to\my.ps1
MSIZAP said: NOTE: MsiZap requires admin privileges to run correctly. The W option requires that the profiles for all of the users be loaded.
That was strange because i was the Admin! So i tried it in a different way. I replaced:
$mymsizap = "\\unc\path\msizap.exe"
Get-WmiObject -class win32_product | where-object { $_.Caption -like "Java*" } | foreach {
$j = " T " + $_.identifyingnumber
& $mymsizap $j
}
But the same error. So i tried it like this:
Get-WmiObject -class win32_product | where-object { $_.Caption -like "Java*" } | foreach {
\\unc\path\msizap.exe T $_.identifyingnumber
}
And it worked. But why is this different and how would i execute it with invoke-expression or "&"?
Gruß Thomas Voß