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.


MattMcNabb
2017-02-13T14:03:54Z
I have several PowerShell scripts that use directory dependencies to process other files, and for this I use the $PSScriptRoot automatic variable. However, when I try to run these scripts from a VisualCron PowerShell task, the value of $PSScriptRoot is null and I tend to have to hard-code a path. Why is this variable not populated? Are any automatic variables populated in the VC PowerShell host? Thanks!
Sponsor
Forum information
Support
2017-02-13T18:56:32Z
Since we are using the PowerShell this Variables is not available. You can try;

$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(‘.\’)

https://msdn.microsoft.c...mp;MSPPError=-2147217396 
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
MattMcNabb
2017-02-13T19:13:08Z
Not sure I understand the above - what prevents this from being available? Are any of the automatic variables available?

Unfortunately, the command above will return the current working directory instead of the path of the currently executing script, and these are not the same thing.
Support
2017-02-15T07:27:10Z
Originally Posted by: MattMcNabb 

Not sure I understand the above - what prevents this from being available? Are any of the automatic variables available?

Unfortunately, the command above will return the current working directory instead of the path of the currently executing script, and these are not the same thing.



I cannot answer if there is an exact equvivalent of your command but the reason some commands does not work is that the PowerShell host is a different engine than PowerShell.exe. It does not have a process by its own - it is hosted in other applications. Because of that, commands and features are slightly different. You always have the option to call PowerShell.exe if you cannot get something to work.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
MattMcNabb
2017-02-16T20:32:57Z
Originally Posted by: Support 

Originally Posted by: MattMcNabb 

Not sure I understand the above - what prevents this from being available? Are any of the automatic variables available?

Unfortunately, the command above will return the current working directory instead of the path of the currently executing script, and these are not the same thing.



I cannot answer if there is an exact equvivalent of your command but the reason some commands does not work is that the PowerShell host is a different engine than PowerShell.exe. It does not have a process by its own - it is hosted in other applications. Because of that, commands and features are slightly different. You always have the option to call PowerShell.exe if you cannot get something to work.



That might be what I do in the short term to resolve this problem, and potentially work toward transforming my project to be less dependent on the script's path. As a workaround, though, is it possible to set the working directory for PowerShell tasks the way that you can for CMD?

Thanks!
Support
2017-02-17T10:51:29Z
Originally Posted by: MattMcNabb 

Originally Posted by: Support 

Originally Posted by: MattMcNabb 

Not sure I understand the above - what prevents this from being available? Are any of the automatic variables available?

Unfortunately, the command above will return the current working directory instead of the path of the currently executing script, and these are not the same thing.



I cannot answer if there is an exact equvivalent of your command but the reason some commands does not work is that the PowerShell host is a different engine than PowerShell.exe. It does not have a process by its own - it is hosted in other applications. Because of that, commands and features are slightly different. You always have the option to call PowerShell.exe if you cannot get something to work.



That might be what I do in the short term to resolve this problem, and potentially work toward transforming my project to be less dependent on the script's path. As a workaround, though, is it possible to set the working directory for PowerShell tasks the way that you can for CMD?

Thanks!



Not right now, please create a Feature request in the Feature requests forum.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top