Powershell unable to find snapin

PowerShell script exchange

Powershell unable to find snapin

Veeam Logoby kjparker » Fri 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?
kjparker
Novice
 
Posts: 5
Liked: never
Joined: Thu Jun 12, 2014 11:54 pm
Full Name: Keith Parker

Re: Powershell unable to find snapin

Veeam Logoby v.Eremin » Fri Jun 13, 2014 10:46 am

What happens if you try to run older PS version? (Say, powershell -version 3.0). Thanks.
v.Eremin
Veeam Software
 
Posts: 13281
Liked: 970 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell unable to find snapin

Veeam Logoby kjparker » Mon 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!
kjparker
Novice
 
Posts: 5
Liked: never
Joined: Thu Jun 12, 2014 11:54 pm
Full Name: Keith Parker

Re: Powershell unable to find snapin

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

Re: Powershell unable to find snapin

Veeam Logoby tdewin » Mon 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.
tdewin
Veeam Software
 
Posts: 1046
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: Powershell unable to find snapin

Veeam Logoby kjparker » Mon Jun 16, 2014 8:58 pm

v.Eremin wrote:
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.

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!
kjparker
Novice
 
Posts: 5
Liked: never
Joined: Thu Jun 12, 2014 11:54 pm
Full Name: Keith Parker

Re: Powershell unable to find snapin

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


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests