Task scheduler launching powershell script

PowerShell script exchange

Task scheduler launching powershell script

Veeam Logoby choldings » Mon Sep 16, 2013 2:57 pm

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
choldings
Enthusiast
 
Posts: 31
Liked: 1 time
Joined: Thu Jun 20, 2013 1:00 pm
Full Name: Colin

Re: Task scheduler launching powershell script

Veeam Logoby nefes » Mon Sep 16, 2013 3:03 pm

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.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Task scheduler launching powershell script

Veeam Logoby choldings » Mon Sep 16, 2013 3:05 pm

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?
choldings
Enthusiast
 
Posts: 31
Liked: 1 time
Joined: Thu Jun 20, 2013 1:00 pm
Full Name: Colin

Re: Task scheduler launching powershell script

Veeam Logoby nefes » Mon Sep 16, 2013 3:20 pm

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.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Task scheduler launching powershell script

Veeam Logoby choldings » Mon Sep 16, 2013 3:31 pm

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.
choldings
Enthusiast
 
Posts: 31
Liked: 1 time
Joined: Thu Jun 20, 2013 1:00 pm
Full Name: Colin

Re: Task scheduler launching powershell script

Veeam Logoby nefes » Mon Sep 16, 2013 3:33 pm

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.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Task scheduler launching powershell script

Veeam Logoby v.Eremin » Mon Sep 16, 2013 3:35 pm

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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Task scheduler launching powershell script

Veeam Logoby choldings » Mon Sep 16, 2013 3:52 pm

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.
choldings
Enthusiast
 
Posts: 31
Liked: 1 time
Joined: Thu Jun 20, 2013 1:00 pm
Full Name: Colin

Re: Task scheduler launching powershell script

Veeam Logoby v.Eremin » Mon Sep 16, 2013 4:19 pm

Thanks, Colin, for coming back and updating the topic with the found resolution; much appreciated.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Task scheduler launching powershell script

Veeam Logoby choldings » Tue Sep 17, 2013 12:52 pm

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.
choldings
Enthusiast
 
Posts: 31
Liked: 1 time
Joined: Thu Jun 20, 2013 1:00 pm
Full Name: Colin

Re: Task scheduler launching powershell script

Veeam Logoby v.Eremin » Tue Sep 17, 2013 12:54 pm

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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: Google [Bot] and 8 guests