Problem with Execute-ProcessAsUser

Calling a PowerShell script using Execute-ProcessAsUser has suddenly stopped working on all the machines in my environment

Execute-ProcessAsUser -Path “$PSHOME\powershell.exe” -Parameters “–ExecutionPolicy Bypass -Command & { & "$dirFiles\user_install_diligent.ps1”; Exit `$LastExitCode }" -Wait -RunLevel HighestAvailable

The command runs ok and returns exit code ‘0’ …
But the script does not actually run

I have been picking the function apart.
The scheduled task is being created ok
And the scheduled task is running ok
I see that the scheduled task actually runs a dynamically created file vbscript file. C:\Users\Public\PSAppDeployToolkit\PSAppDeployToolkit-ExecuteAsUser.vbs

So, I focused on seeing if I can get that piece of vbscript to run.
I created a batch file to run the script

cscript //nologo C:\Users\Public\PSAppDeployToolkit\PSAppDeployToolkit-ExecuteAsUser.vbs /D
echo Return code = %ErrorLevel%

To give me more feedback, I modified ‘PSAppDeployToolkit-ExecuteAsUser.vbs’ so it would write some output to a text file.

strCommand = chr(34) & “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” & chr(34) & " –ExecutionPolicy Bypass -Command & { & " & chr(34) & “C:\Temp\Diligent Boards v2.10.2.1869 R1.00\Files\user_install_diligent.ps1” & chr(34) & “; Exit $LastExitCode }”
set oWShell = CreateObject(“WScript.Shell”)
intReturn = oWShell.Run(strCommand, 0, true)

Set objFSO=CreateObject(“Scripting.FileSystemObject”)
outFile=“c:\temp\vbscript_log_file.txt”
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "strCommand … " & strCommand & vbCrLf
objFile.Write "intReturn … " & intReturn & vbCrLf
objFile.Close

WScript.Quit intReturn

The text file then contains this …

strCommand … “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” –ExecutionPolicy Bypass -Command & { & “C:\Temp\Diligent Boards v2.10.2.1869 R1.00\Files\user_install_diligent.ps1”; Exit $LastExitCode }

intReturn … 0

So I opened up an elevated command prompt and pasted that command in
And get the following error…

Cannot process the command because of a missing parameter. A command must follow
-Command.

I have tried many variations around trying to get that command line work, nada no success at all with various errors.
But then I have little doubt it not the command that is the problem.
Because I had no problem with the script until just recently, numerous users have been running the script to install the software, then all of a sudden it doesn’t !?? So weird.

I know this is probably not really a problem with PowerShell Application Deployment Toolkit and more some sort of change in my environment, and I can’t pin point what has actually changed?

I have now achieved what I needed using a different method, I am dynamically building a batch file from within the script to run the PowerShell script, and then calling that batch file using Execute-ProcessAsUser, that runs fine.
Only that now a DOS box briefly pops up, where as using the vbscript method it didn’t.

For those interested on why I am even doing such a long winded way of running the ‘user_install_diligent.ps1’ script.
Basically I am side loading an AppX package into Windows 8.1, in my environment Powershell is disabled for the users, so the Deploy-Application script sets it up so that script will run for them.

Really interested if anyone has had similar experiences lately and maybe someone else will find my explorations useful.

I think your problem is the path "C:\Temp\Diligent Boards v2.10.2.1869 R1.00.\Files
Make the path smaller C:\ Diligent_Boards\Files…