Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.

Within the "Execute" task type, there is a "Working directory" setting. However, I can't figure out a way to execute my PowerShell script so that it runs in its current folder. There are several PowerShell built-in commands that should be able to accomplish this, but none of them seem to work.

$PSScriptRoot: This should return the root of the script that is currently running. From within the PowerShell task, however, this appears to be $null
( Split-Path "$( $myInvocation.MyCommand.Path )" ): This is an older trick, but should resolve as the current script directory. This command fails, because the myInvocation variable isn't defined.
$Pwd: This should and does return the current execution directory. However, when running from a PowerShell task, it always returns "C:\Program Files (x86)\VisualCron\PowerShell" which makes sense, because that's the directory that TaskPowerShell.exe is running from. However, if I were able to specify a "Working directory" then this would return that directory.

I also tried "(Get-Location).Path" and "(Resolve-Path .\).Path", both of which resolve the same as $Pwd.

I need the script directory in order to execute functions, and I can't imagine that I'm the only one that would find this necessary for almost all of my scripts. That fact leads me to believe there is a way to do it that I'm missing.

I could add a parameter to pass to the PowerShell script, but then I would need to add this to all of my scripts, and it seems like a hack workaround.
I would just use the "Execute" task type, and run Powershell.exe, but then I'm not able to pass VisualCron job variables, nor am I able to execute from a UNC path.

Is there any other way that I could accomplish this without changes to my (working) scripts?

Thanks in advance!
Forum information
Please try this build where you can set the working directory in the PowerShell Task:


Let us know the result!
Please like  VisualCron on facebook!
Scroll to Top