PowerShell script exchange
Post Reply
kjparker
Novice
Posts: 6
Liked: never
Joined: Jun 12, 2014 11:54 pm
Full Name: Keith Parker
Contact:

Powershell unable to find snapin

Post by kjparker » Jun 13, 2014 12:10 am

I am in the process of setting up my new veeam environment with my tape library.

I am having problems with the Import-VBRTapeMedium applet when trying to run it from the regular powershell (via a .ps1 file)

If I launch from within veeam the powershell console, the following command:

Code: Select all

Add-PSSnapin VeeamPSSnapin
Get-VBRTapeLibrary | Import-VBRTapeMedium -RunAsync
It works exactly as expected, and moves all cartridges from the mail slot, and back into the pool.

If I run the same code from within the ISE (as admin) it also works.

If I run the same code from Powershell ( as admin) I get the following:

Code: Select all

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 4.
At line:1 char:1
+ Add-PSSnapin "VeeamPSSnapin"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (VeeamPSSnapin:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
I dont understand why it works in ISE, but not in Powershell. Any thoughts as to where I should start looking?

veremin
Product Manager
Posts: 16884
Liked: 1433 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell unable to find snapin

Post by veremin » Jun 13, 2014 10:46 am

What happens if you try to run older PS version? (Say, powershell -version 3.0). Thanks.

kjparker
Novice
Posts: 6
Liked: never
Joined: Jun 12, 2014 11:54 pm
Full Name: Keith Parker
Contact:

Re: Powershell unable to find snapin

Post by kjparker » Jun 16, 2014 4:08 am

Thanks for the response. I'm not sure what changed on the system, however it is now working. I wish I knew what it was that I was either doing wrong or did to fix it, but I really dont know!

I now need to expand the script to move the imported tapes to the free pool, and figure out how to get Veeam (or other application) to launch the script prior to starting the tape job... But those are questions for another thread!

veremin
Product Manager
Posts: 16884
Liked: 1433 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell unable to find snapin

Post by veremin » Jun 16, 2014 9:10 am

I now need to expand the script to move the imported tapes to the free pool
Tape mediums can be moved to Free Media Pool via Move-VBRTapemedium commandlet.
figure out how to get Veeam (or other application) to launch the script prior to starting the tape job
Windows Scheduler should be your way to go. Just create a script that starts a pre-job command, and, then, proceeds to job execution.

Thanks.

tdewin
Veeam Software
Posts: 1430
Liked: 460 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Powershell unable to find snapin

Post by tdewin » Jun 16, 2014 1:46 pm

Could it be that you launched a 32 bit version of the ISE. The VeeamPSSnapin is 64-bit only.

kjparker
Novice
Posts: 6
Liked: never
Joined: Jun 12, 2014 11:54 pm
Full Name: Keith Parker
Contact:

Re: Powershell unable to find snapin

Post by kjparker » Jun 16, 2014 8:58 pm

v.Eremin wrote: Tape mediums can be moved to Free Media Pool via Move-VBRTapemedium commandlet.
Windows Scheduler should be your way to go. Just create a script that starts a pre-job command, and, then, proceeds to job execution.

Thanks.
Thanks!

I had a play yesterday, and I was able to get the script to work the way I wanted it, Code below for anyone who is interested:

Code: Select all

Add-PSSnapin VeeamPSSnapin
$tape = Get-VBRTapeMedium -offline
Move-VBRTapeMedium -Medium $tape -MediaPool Free -Confirm:$false
Get-VBRTapeLibrary | Import-VBRTapeMedium -RunAsync
In a nutshell, it queries the tape library to see what tapes are in the mail slots, assigns them the variable $tape, moves them to free, and iports them back into the library.

I hadnt thought about scheduling the jobs via windows scheduler, I was always just using veeam scheduling, but this does seem a lot more flexible! I'll look into it more! Thanks for the tip!

veremin
Product Manager
Posts: 16884
Liked: 1433 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell unable to find snapin

Post by veremin » Jun 17, 2014 8:41 am

While working with PowerShell scripts it's always advisable to use Windows Scheduler, as it gives you required flexibility. Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest