PowerShell script exchange
Post Reply
ShawnKPERS
Enthusiast
Posts: 61
Liked: 4 times
Joined: Apr 29, 2011 3:55 pm
Full Name: Shawn Nix
Contact:

Running Powershell Script Post Backup

Post by ShawnKPERS »

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?
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Running Powershell Script Post Backup

Post by ThomasMc »

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
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Running Powershell Script Post Backup

Post by ThomasMc » 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"
ShawnKPERS
Enthusiast
Posts: 61
Liked: 4 times
Joined: Apr 29, 2011 3:55 pm
Full Name: Shawn Nix
Contact:

Re: Running Powershell Script Post Backup

Post by ShawnKPERS »

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!
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Running Powershell Script Post Backup

Post by ThomasMc »

Glad I could help :)
ISExpress
Influencer
Posts: 16
Liked: never
Joined: Jun 27, 2011 1:50 pm
Full Name: ISExpress
Contact:

Re: Running Powershell Script Post Backup

Post by ISExpress »

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.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Running Powershell Script Post Backup

Post by ThomasMc » 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
}
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests