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.


Wellington
2013-07-14T16:01:23Z
I have created a poweshell script in which I am trying to find out the current directory in which the ps1 file is executing. When in execute the script from powershell command prompt, i am able to get the path properly. Using the path I am trying to Read some configuration values from a file which is located in the same folder where the script is located.

But once I configure to execute the script as a power shell task in visualCron, I am not able to get the path where my script is executed.

The sample code which I am using is provided below. The output from both the environments, i.e. powershell command and visualCron powershell task are provided below.

echo "##########-START-##########" > \\Server\test\log.txt
echo $MyInvocation.InvocationName >> \\Server\test\log.txt
echo "##########-DONE-##########" >> \\Server\test\log.txt

Output From Powershell Command
##########-START-##########
\\Server\test\test.ps1
##########-DONE-##########

Output from VisualCron server when the same script mentioned above is executed. there is no output path.
##########-START-##########

##########-DONE-##########


My understanding is, Visual Cron reads the content of the ps1 file and then executes it from within the VisualCron environment. If my understanding is correct, how can I get the path of the script file in my power shell script.

Thanks in advance.
Anoop
Sponsor
Forum information
Support
2013-07-15T09:01:37Z
I think you can use these two:

[System.IO.Directory]::GetCurrentDirectory()
[System.IO.Directory]::SetCurrentDirectory("C:\Program Files")

We do not automatically set the current directory to the path of the script file.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top