PowerShell script works locally but can't find filepath in a worklet
Automox utilizes 32-bit PowerShell for Worklets. This can cause scripts that have been tested locally with Windows PowerShell to have trouble with paths.
Symptoms
Running the Worklet script locally in Windows PowerShell works as intended but fails in the Worklet with one of these errors:
- Cannot find path error
- ItemNotFoundException
Steps to resolution
- Test the script in Windows PowerShell (x86) to confirm the same error is what is received from the Worklet.
- Wrap the script within a scriptblock.
Example:
$scriptBlock = {
YOUR CODE HERE
}
$exitCode = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptblock
Exit $exitCode