I am by no means a PowerShell expert; I have spent a good while googling this, but haven't found an answer.
The basic idea of my script is to run a Microsoft tool called appcert.exe with command-line arguments. appcert.exe returns 0, 1, or -1; I am checking it with $lastexitcode
.
appcert.exe only runs on Windows 7 and Windows 8, so I have run my script on both.
Everything works fine on Windows 7x64 (PS version = 2.0). I can manually run all the same steps. I see the output of appcert.exe in the same PS window.
Different story on Windows 8x64 (RTM), where PS version = 3.0, CLRVersion = 4.0.30319.17929.
Sometimes, appcert.exe runs "inline" (like it did in Win7); other times, a command window is launched, the appcert.exe output flies by, and command window closes. The PS window that called it can't check $lastexitcode
(which, by the way, is not set at all).
I tried all PS versions on machine, and results are as follows:
appcert.exe is launched in separate window in these instances:
- In PowerGUI 3.2.0.2237 (uses PS 2.0)
- In regular PowerShell (non-admin)
- In Windows PowerShell ISE (non-admin)
appcert.exe is launched inline in these instances:
- Ran Powershell as administrator
- Ran ISE as administrator
Behavior above is obtained whether I:
- Launch script, which calls the appcert command like this:
& $CertToolPath
- cd to the home direcotry of the tool and type .\appcert.exe
- Run this:
Cmd /c appcert.exe
- Run this:
Invoke-expression –command appcert.exe
- Run this:
[system.diagnostics.process]::start("appcert.exe")
My colleagues are equally stumped by this.
My machine is in a test domain, not a workgroup. I log into the machine as an admin of the test domain, so theoretically, I'm already an admin.
I install the MS tool as that admin, too. In fact, I never do anything as the machine's local admin. Any ideas? :)
Many thanks in advance, Tania