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


Guest
2009-04-13T18:09:20Z
I have some powershell scripts that I'm trying to run, but VisualCron will only run them if I set the execution context to 'Foreground execution'. I've tried both bat files and directly running the the powershell executable but they all fail unless I do the foreground execution.


Are there plans to nativly support Powershell scripts so that I don't need to have these run in the foreground?
Sponsor
Forum information
Support
2009-04-13T18:44:44Z
Yes, it might be interesting with native support but for now you can execute PowerShell scripts just the way you execute Perl, PHP and other script languages with scripting engines.

What you need to do is to point out the engine as command, in this case something like:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Then use your PowerShell command as argument like:

Get-Process
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Guest
2009-04-13T18:58:52Z
Support wrote:

Yes, it might be interesting with native support but for now you can execute PowerShell scripts just the way you execute Perl, PHP and other script languages with scripting engines.

What you need to do is to point out the engine as command, in this case something like:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Then use your PowerShell command as argument like:

Get-Process



I've tried that and it won't execute for me unless I do the foreground execution. My scrips are running other exe commands which may be causing a problem, but I would think that would be allowed.

I'm using the following command when I try to run the powershell script:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Argument:

-command "C:\Data\Scripts\ProcessFiles.ps1"

Here's an example of a script I'm running:

write-host "Process files..."

$Files = get-childitem $FilePath | where-object {$_.name -like "*foobarfiles*"}

foreach ($file in $Files)
{
  if ($file -ne $NULL)
  {
    $filetoProcess = $FilePath + $file
    & $Admin /FILE:"$filetoProcess"
    $filetoProcess | move-item -destination $OutputPath
  }
}


Am I doing something wrong? I assume by your response you don't have any issues running powershell scripts?
Support
2009-04-13T19:21:32Z
We have not tried any scripts before. I could not run your script as is because it needs to be signed. Do you think you can sign it and attach it?

What error do you get in the output column?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Guest
2009-04-14T17:09:56Z
We're not running with signed scripts. Here's the command to turn off the requirements for signed scripts

Set-ExecutionPolicy Unrestricted 




Support
2009-04-14T19:13:11Z
Thanks. But problem is that I am no expert at PowerShell. I was able to run the file which printed "Process files..." to output column.

Do you get any error in output column? Or std error column?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Guest
2009-04-14T22:30:25Z
ok. I've got an example you should be able to run. I'm copying files from one temp location to another. When I run it on the command line it will copy the files. When you run it in Visual Cron it will not copy the files. Rename the attached file to copyfiles.ps1

To run it use the following:

powershell -command ./"copyfiles.ps1"

$Admin = "C:\windows\system32\xcopy.exe"
$FilePath = "C:\Temp"
$OutputPath = "C:\Windows\Temp"


write-host "Process  files..."

$Files = get-childitem $FilePath | where-object {$_.name -like "*.txt"}

foreach ($file in $Files)
{
  if ($file -ne $NULL)
  {
    $filetoProcess = $FilePath + "\" + $file
    
    & $Admin "/Y" "$filetoProcess" "$OutputPAth"

   
  }
}
Support
2009-04-14T22:45:45Z
Thanks for the sample.

The problem is that PowerShell seems to handle the working directory very differently. The problem is that it does not find any files in whatever folder it is looking at. So, you have to options:

1. find a way to set this working directory or hard code directory to search in in some other way
2. check "Use shell execute" option in Execute settings. The disadvantage with this is that you won't get the output.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Guest
2009-04-14T23:06:01Z
Support wrote:

Thanks for the sample.

The problem is that PowerShell seems to handle the working directory very differently. The problem is that it does not find any files in whatever folder it is looking at. So, you have to options:

1. find a way to set this working directory or hard code directory to search in in some other way



I don't understand what you mean by this. The entire path for the location for the get-files is in the variable

Support wrote:


2. check "Use shell execute" option in Execute settings. The disadvantage with this is that you won't get the output.



When I turn on shell execute I get a result of "Incorrect Function" and it looks like it didn't run at all.

Support
2009-04-14T23:13:29Z
1. I don't know why but that does not work. It does not find the files. I don't know which function fails internally within PowerShell but it does not find any files and because of that it does not work unless you do the workarounds.

2. Maybe because you have not specified the full path to the script? The script worked for me.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Guest
2009-04-14T23:52:14Z
Support wrote:

1. I don't know why but that does not work. It does not find the files. I don't know which function fails internally within PowerShell but it does not find any files and because of that it does not work unless you do the workarounds.


2. Maybe because you have not specified the full path to the script? The script worked for me.




I have the entire path on the script. I'm able to get it running without being a 'foreground' process if I run with the following:

Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -command "c:\pathToScript\copyfiles.ps1"

Miscellaneous (all unchecked)

Run Task as:

my credentials
Login Type: With Profile -- Run with API Code


I have a feeling that powershell requires the user profile from the local computer. I'm running VisualCron under a domain user and it might not have any settings on this local computer. I would expect the same problem with doing a default install of VisualCron and using the 'Network and because I have VisualCron using 'Network Service' or 'Local System'


I'm going to try this settings on my other more complicated scripts and see if I can get them to run

Support
2009-04-15T08:55:16Z
Did you try to check "Use shell execute"?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Guest
2009-04-15T17:09:15Z
Support wrote:

Did you try to check "Use shell execute"?



yes.

When I turn on shell execute I get a result of "Incorrect Function" and it didn't didn't run at all.
Support
2009-04-15T17:10:40Z
What if you use "Use shell execute" and remove the Credential?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Guest
2009-04-15T17:22:39Z
Support wrote:

What if you use "Use shell execute" and remove the Credential?



I tried it first without the credentials and the option set but I received the error.

I then unchecked it and picked the credentials and used the 'API' setting. That worked. Using 'managed code' didn't work.

Obviously there is something going on because that is different from how you were able to get it working. I'm running the VisualCron service under 'Local System' which I believe is the default installation setting.


I've changed the settings for my other scripts and they all appear to be working. What I haven't tested yet is the return values to the notification responses for errored scripts (a critical scenario for me). I'm going to do that next.
Support
2009-04-15T19:20:57Z
To get it to work I use:

Service running as SYSTEM
API (not managed)
Use shell execute
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Support
2011-04-07T12:59:51Z
Please try this new version with PowerShell built in:

http://www.visualcron.co...osts&m=8403#post8403 
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
jm
2011-12-14T20:59:13Z
Hi,

We are using v6.9.0.4 and had the same issue when trying to schedule a powershell script.
I found the issue on our side was with the arguments.
In the command field you need to add - C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
In the arguments field you need to add -
-command E:\Folder\Folder\script.ps1

I had the whole path enclosed with double quotes "". as soon as I removed the quotes it started working.

Not using shell execute.

Cheers
Support
2011-12-14T22:34:22Z
Great, thanks for the update.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Scroll to Top