Why's it breaking? Powershell command not doing what it should

Does anyone have any idea why this wouldn’t work?

When ran manually it creates the log file like I’ve asked it to but when ran from the fixlet it’s like the PS is never ran as the log file never gets created.

waithidden {pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry) } -ExecutionPolicy Bypass -File "{pathname of find file "*.ps1" of folder "c:\temp\mdfi"}" > "c:\temp\mdfi\install.log"

The log file shows:

   Command started - waithidden C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "c:\temp\mdfi\file.ps1" > "c:\temp\mdfi\install.log" (action:541144103)
At 15:32:17 +0000 - 
   Report posted successfully
At 15:32:18 +0000 - actionsite (http://bfserver.com:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded (Exit Code=0) waithidden C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "c:\temp\mdfi\file.ps1" > "c:\temp\mdfi\install.log" (action:541144103)

Ah, sorry I hadn’t considered this on your other posting - the output redirection is, I believe, a function of the shell (cmd.exe provides it, I think PowerShell does not).

I usually get around this by invoking CMD to launch PowerShell…the doubled double quotes here are intentional & necessary -

waithidden cmd.exe /c ""{pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry) }" -ExecutionPolicy Bypass -File "{pathname of find file "*.ps1" of folder "c:\temp\mdfi"}" > "c:\temp\mdfi\install.log""

2 Likes

I actually can’t believe I didn’t think about that :frowning:

Thanks again Jason, saved my bacon again :smiley:

1 Like

I use this approach too for PowerShell scripts. I would also recommend testing via in the fixlet debugger using cmd.exe /k so you can see the script output in case the script throws any errors that would otherwise go unseen with the /c arg :wink:

2 Likes