Powershell Script Not running

I have a powershell wrapper that downloads the script to the client and them moves it to the c:\temp folder on the machine. It then uses the following command line in the wrapper to launch the script:

waithidden "{parameter "PowerShellexe"}" -file "c:\temp\testing.ps1"

This works for other scripts that I am running, such as copying files from network share to the local box, but this script only starts the Start-Transcript -Path c:\temp\output.txt -Append which is the first line of the script and never executes the rest. Is there something I should be doing different within the wrapper to launch and run a script that will run local without any issues. It is a script to fail over a SQL cluster.

Which version of Powershell? There were transcript issues with older versions. Some of those have been fixed in WMF 5.0 that was just re-released.

Try a powershell without transcript to see if the issue is isolated to the transcript function.

I am using powershell 4.0 and even with out transcript powershell completes successfully but script never runs. I placed the transcript there to make sure powershell.exe was launch the script.

If I run the script local on the box it runs fine even with transcript.

Can you share an example? What is the signing policy? Which OS are you running it on?

We have the execution policy set to bypass and is running on 2012R2 OS. As for the script I really can not post it but it basically has some functions and main code that fail over s SQL cluster.

Here is my Action script:

//============================================================================
//PowerShell Script…
//
//THIS TASK WILL DOWNLOAD AND EXECUTE A POWERSHELL SCRIPT
//============================================================================
//1. Save old ExecutionPolicy value
//parameter “PolicyExisted”="{exists value “ExecutionPolicy” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of registry}"
//parameter “oldExecutionPolicy”="{if (parameter “PolicyExisted” as boolean) then (value “ExecutionPolicy” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of registry as string) else “”}"
//============================================================================
//2. set to ExecutionPolicy=Unrestricted and set the powershell executable location
//we need to determine what the current execution policy is so we can put it back when we’re done.
//regset “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” “ExecutionPolicy”=“Unrestricted”
//parameter “PowerShellexe” = “C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe”
//============================================================================
//3. If C:\temp doesn’t exist, create it
//
if {not exists folder “c:\temp”}
waithidden cmd.exe /C mkdir c:\temp
else
endif

//============================================================================
//4.
download as vacate_server_bigfix_testing.ps1 http://bigfixserver:52311/Uploads/vacate_server_bigfix_testing.ps1
continue if {(sha1 of it = “d3b0af46b4c33dd4584e53a1293aba4d59bded16”) of file “vacate_server_bigfix_testing.ps1” of folder “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\actionsite__Download”}
dos copy /Y __Download\vacate_server_bigfix_testing.ps1 c:\temp\vacate_server_bigfix_testing.ps1
//============================================================================
//5. Execute PowerShell with ps1 script file
waithidden “{parameter “PowerShellexe”}” -file “c:\temp\vacate_server_bigfix_testing.ps1”

c:\temp\vacate_server_bigfix_testing.ps1

//============================================================================
//6. Restore ExecutionPolicy back
//if {parameter “PolicyExisted” as boolean}
//regset “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” “ExecutionPolicy”="{parameter “oldExecutionPolicy”}"
//else
//regdelete “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” “ExecutionPolicy”
//endif
//============================================================================
//7. Cleanup Scripts
//delete “c:\temp\vacate_server_bigfix_testing.ps1”
//============================================================================

You’re calling “{parameter “PowerShellexe”}” , but that parameter is commented out earlier.

Yeah I removed that sorry. That was me testing something. That has been un commented and still same issue. The script does not execute.

Try this:

waithidden "C:\Windows\SysNative\WindowsPowerShell\v1.0\PowerShell.exe" -NonInteractive -NoLogo  -file "c:\temp\vacate_server_bigfix_testing.ps1"

Powershell seems to default to x86 Powershell.exe. Some scripts are picky and need to be run from the x64 Powershell.exe. This specific path should force it to use the x64 version.

2 Likes

That worked thank you…

BigFix is 32bit so it defaults to using 32bit powershell and similar things in the system folders.

You can disable WOW redirection, or use the special path: C:\Windows\SysNative to get around this limitation.