PowerShell script exchange
Post Reply
choldings
Enthusiast
Posts: 31
Liked: 2 times
Joined: Jun 20, 2013 1:00 pm
Full Name: Colin
Contact:

Task scheduler launching powershell script

Post by choldings »

I am trying to backup an Symantec Enterprise Vault server with Veeam. I need to launch a powershell script with task scheduler that puts the vault store into "backup mode" and then launch the veeam job.

My problem is this, if I launch the script manually, it works great. If I let task scheduler launch it, it never puts the server into backup mode, but it does kick off the veeam job.

The task runs as the veeam service account and it has permission to do what it needs to do in enterprise vault (if I run it manually in a powershell window launched as this user it works fine)

C:\Windows\system32\Windowspowershell\v1.0\powershell and then the argument is the path to the .ps1 script.

I know the script launches because it runs the veeam job.

Is there a way to make task scheduler run the script in whatever the way it runs if I do it manually. Doing it through task scheduler isn't doing something right as far as the enterprise vault part of the script goes.

Any insight would be much appreciated!

Thanks
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Task scheduler launching powershell script

Post by nefes »

Do you use some Symantec-specific powershell commandlets? If yes, you should import corresponding module or snap-in.
It is also worth checking if the user starting your .ps1 file have the same permissions as the one running it manually.
You could also write output of your script into some log file to find out what errors are happening during its execution.
choldings
Enthusiast
Posts: 31
Liked: 2 times
Joined: Jun 20, 2013 1:00 pm
Full Name: Colin
Contact:

Re: Task scheduler launching powershell script

Post by choldings »

nefes wrote:Do you use some Symantec-specific powershell commandlets? If yes, you should import corresponding module or snap-in.
It is also worth checking if the user starting your .ps1 file have the same permissions as the one running it manually.
You could also write output of your script into some log file to find out what errors are happening during its execution.
Yes it does, I have installed the console needed to launch the commands via the veeam server. If I launch the same script outside of task scheduler, it works fine.

It is the same user account launching it manually as the one task scheduler is using.

How would I output the running of the script to a log file?
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Task scheduler launching powershell script

Post by nefes »

You can call it from task scheduler like:

Code: Select all

powershell .\MyScript.ps1 > c:\output.txt
Also you may want to add some Write-Host commands to see, for example, values of key variables used to call your commandlets.
choldings
Enthusiast
Posts: 31
Liked: 2 times
Joined: Jun 20, 2013 1:00 pm
Full Name: Colin
Contact:

Re: Task scheduler launching powershell script

Post by choldings »

nefes wrote:You can call it from task scheduler like:

Code: Select all

powershell .\MyScript.ps1 > c:\output.txt
Also you may want to add some Write-Host commands to see, for example, values of key variables used to call your commandlets.
It appears that when it runs via task manager, it thinks that the Enterprise vault addin doesn't exist.

Code: Select all

WARNING: The following errors occurred when loading console C:\Program Files 
(x86)\Enterprise Vault\EVShell.psc1: 
Cannot load Windows PowerShell snap-in 
Symantec.EnterpriseVault.PowerShell.Snapin because of the following error: The 
Windows PowerShell snap-in 'Symantec.EnterpriseVault.PowerShell.Snapin' is not 
installed on this machine.
But if you run it manually, it has no problem with it.
nefes
Veeam Software
Posts: 643
Liked: 162 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Task scheduler launching powershell script

Post by nefes »

So all you need is to load snap-in to the context of your script. Try to add

Code: Select all

Add-PSSnapIn 'Symantec.EnterpriseVault.PowerShell.Snapin'
at the beginnig of your script. It should solve your problem.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Task scheduler launching powershell script

Post by veremin »

Additionally, does the whole script activity take place locally or the script has some “remote” parts, as well (trying to connect to remote computer, etc.)? Thanks.
choldings
Enthusiast
Posts: 31
Liked: 2 times
Joined: Jun 20, 2013 1:00 pm
Full Name: Colin
Contact:

Re: Task scheduler launching powershell script

Post by choldings »

I figured it out. I had read that I needed to use the 32bit powershell so I made the path to launch it c:\windows\system32\WindowsPowershell\v1.0

Changing the path to SYSWOW64 made the script launch with the add-in.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Task scheduler launching powershell script

Post by veremin »

Thanks, Colin, for coming back and updating the topic with the found resolution; much appreciated.
choldings
Enthusiast
Posts: 31
Liked: 2 times
Joined: Jun 20, 2013 1:00 pm
Full Name: Colin
Contact:

Re: Task scheduler launching powershell script

Post by choldings »

No problem, I hope it saves the next guy an hour or so hehe

Can Veeam 7 launch this pre activity script or do I have to use task scheduler? I don't see any GUI options for a pre activity script.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Task scheduler launching powershell script

Post by veremin »

There is no “pre-activity” option available in the job settings. Though, you can create a Scheduled Task and launch everything within it (start pre-activity, then, execute a job). Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests