PowerShell Working Directory - VisualCron - Forum

Community forum

ddtiChamm
2018-01-15T22:01:53Z
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!
Support
2018-01-19T15:42:03Z
Please try this build where you can set the working directory in the PowerShell Task:

https://www.visualcron.c....aspx?g=posts&t=7786 

Let us know the result!
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top