Running Powershell Script Post Backup

PowerShell script exchange

Running Powershell Script Post Backup

Veeam Logoby ShawnKPERS » Mon Apr 23, 2012 11:08 pm

Is it possible to run a powershell script in the "Post Job Activity" command box? I know the answer is yes but I am running into a wall trying to figure out how, I believe I am running into the issue that Veeam will run the script as the local system account and that powershell needs a little more access in order to run. I am currently trying to put the script in Windows task scheduler and then have Veeam post job run the scheduled task but I seem to be running into the issue of needing to supply a user name and password to start the task. I would like to avoid putting this info in the backup job if possible. I am also looking into installing third party "runas" programs as well but I do not like this option either.

Am I overlooking a simple solution to this problem? Is there a better way to run a powershell script post backup?
ShawnKPERS
Enthusiast
 
Posts: 49
Liked: 4 times
Joined: Fri Apr 29, 2011 3:55 pm
Full Name: Shawn Nix

Re: Running Powershell Script Post Backup

Veeam Logoby ThomasMc » Tue Apr 24, 2012 3:02 pm

There are many ways to skin this cat but I'll need to check out if indeed Veeam runs post tasks as system as it doesn't make sense to me why it would
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Running Powershell Script Post Backup

Veeam Logoby ThomasMc » Tue Apr 24, 2012 5:43 pm 1 person likes this post

Had a little test and ran a script in the PJA but it didn't run as the system account, I used this to trigger it(entered into the job setting and not using "Task Scheduler")

Code: Select all
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -File "C:\Get_Username.ps1"
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Running Powershell Script Post Backup

Veeam Logoby ShawnKPERS » Tue Apr 24, 2012 6:45 pm

Thomas you have saved my bacon again, I was looking up and down for a solution that I could live with and had little luck. Thanks for finding a very simple solution!
ShawnKPERS
Enthusiast
 
Posts: 49
Liked: 4 times
Joined: Fri Apr 29, 2011 3:55 pm
Full Name: Shawn Nix

Re: Running Powershell Script Post Backup

Veeam Logoby ThomasMc » Tue Apr 24, 2012 7:16 pm

Glad I could help :)
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Running Powershell Script Post Backup

Veeam Logoby ISExpress » Fri May 04, 2012 8:48 am

I thought this issue was resolved but I’m still getting issues with running post job activity commands to kick of another Veeam job.

We have post job commands running which kick off other Veeam jobs we have. The final Veeam job then kicks of another script which kicks of the backup to tape using Symantec Backup exec. If all these scripts are run manually they work fine without any issue. The post script command in Job1 works perfect as well but when we run the same command for the end of job 3 it doesn’t work.

Below are the commands which are run:

In the post script activity area we run .cmd commands as it doesn’t accept Powershell commands but the .cmd runs the Powershell commands.


Run in Job1 - Veeam Run Job2 ps1.cmd which has the script: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -File "C:\Backup Scripts\Run Veeam Job2.ps1"
Run in job3 - Veeam Run Job4 ps1.cmd which has the script C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -File "C:\Backup Scripts\Run Veeam Job4.ps1"

Powershell statements:

(Run Veeam job2.ps1)

Add-PSSnapin VeeamPSSnapin
$job1 = Get-VBRJob -name "Job2 - Database Services"
Start-VBRJob -job ($job1)

(Run Veeam job4.ps1)

Add-PSSnapin VeeamPSSnapin
$job1 = Get-VBRJob -name "Job4 - Infrastructure Services"
Start-VBRJob -job ($job1)

The Veeamjob2.ps1 runs fine. So once job1 finishes, it kicks of the command script which then kicks of the Powershell script (Run Veeam job2.ps1), the job2 veeam job begins

But

Once Job3 has finished, it doesn’t kick of the Run Veeam job4.ps1?

Don’t understand why as the command is the same but we have amended the script to reflect the different in job name.

Why does 1 job work successfully and not the other? Both jobs 1 and 3 kick off at the same time.
ISExpress
Influencer
 
Posts: 16
Liked: never
Joined: Mon Jun 27, 2011 1:50 pm
Full Name: ISExpress

Re: Running Powershell Script Post Backup

Veeam Logoby ThomasMc » Fri May 04, 2012 1:47 pm 1 person likes this post

Got a bit ahead of myself so I changed this post :) Not sure why yours is failing but I tested with this and the jobs chained as expected

Job1 - Post Job Activity
Code: Select all
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -Command "&{C:\VeeamScripts\Chainey.ps1 -JobName Job2}"


Job3 - Post Job Activity
Code: Select all
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -Command "&{C:\VeeamScripts\Chainey.ps1 -JobName Job4}"


Chainey.ps1 and was saved in "C:\VeeamScripts"
Code: Select all
param($jobName)

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

if ($jobName) {
   Get-VBRJob -Name "$jobName" | Start-VBRJob -RunAsync
}
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 7 guests