-
- Novice
- Posts: 3
- Liked: never
- Joined: Feb 20, 2014 4:13 pm
- Full Name: Shane O'Neill
PowerShell via C# Questions
Hi,
I'm new to using Veeam... I am trying to automate the replication of VM's in our environment using PowerShell and C#... I have the PowerShell script working well but when I try to run it in C# (so that I can do batches via multithreading), I have a problem... The Veeam PS snapin does not load for me... Any other PS snapin that I try to load via C# works just fine but the Veeam one does not... Has anyone tried to do this before with any success?
Second question, I noticed that someone mentioned on a different post that you could reference some .dll files from the Veeam install to use in C#? Is there any reference material for these dll's and how they can be used in C#?
Shane...
I'm new to using Veeam... I am trying to automate the replication of VM's in our environment using PowerShell and C#... I have the PowerShell script working well but when I try to run it in C# (so that I can do batches via multithreading), I have a problem... The Veeam PS snapin does not load for me... Any other PS snapin that I try to load via C# works just fine but the Veeam one does not... Has anyone tried to do this before with any success?
Second question, I noticed that someone mentioned on a different post that you could reference some .dll files from the Veeam install to use in C#? Is there any reference material for these dll's and how they can be used in C#?
Shane...
-
- VP, Product Management
- Posts: 27377
- Liked: 2800 times
- Joined: Mar 30, 2009 9:13 am
- Full Name: Vitaliy Safarov
- Contact:
Re: PowerShell via C# Questions
Hello Shane,
1. What kind of error do you receive? Can you please give us a bit more details on automation you're trying to achieve with C# and PS?
2. There is no such references available.
Thank you!
1. What kind of error do you receive? Can you please give us a bit more details on automation you're trying to achieve with C# and PS?
2. There is no such references available.
Thank you!
-
- Novice
- Posts: 3
- Liked: never
- Joined: Feb 20, 2014 4:13 pm
- Full Name: Shane O'Neill
Re: PowerShell via C# Questions
Hi Vitaliy,
I don't get any error, just that I can't load the Veeam PowerShell snapin via C#...
Here is a code example... I am adding the Veeam snapin and the VMWare snapins that I also have installed... I then call them to verify that they loaded...
private void example()
{
Runspace rs = RunspaceFactory.CreateRunspace();
rs.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = rs;
ps.AddScript("Add-PSSnapin VeeamPSSnapin");
ps.AddScript("Add-PSSnapin VMware.*");
ps.AddScript("Get-PSSnapin");
try
{
foreach (PSObject result in ps.Invoke())
{
Console.Write(result.ToString());
}
}
catch(Exception e)
{
rs.Close();
}
rs.Close();
}
}
This is the output that I get...
Microsoft.PowerShell.Diagnostics
Microsoft.PowerShell.Core
Microsoft.PowerShell.Utility
Microsoft.PowerShell.Host
Microsoft.PowerShell.Management
Microsoft.PowerShell.Security
Microsoft.WSMan.Management
VMware.VimAutomation.Cloud
VMware.VimAutomation.Core
VMware.VimAutomation.License
VMware.VumAutomation
The Veeam PS snapin is not loading... If I do it manually in PowerShell, it works... So I guess I am asking if anyone has tried to do it the same way as me and successed? Or is there something different about the Veeam snapin that I am missing...
Thanks!
Shane...
I don't get any error, just that I can't load the Veeam PowerShell snapin via C#...
Here is a code example... I am adding the Veeam snapin and the VMWare snapins that I also have installed... I then call them to verify that they loaded...
private void example()
{
Runspace rs = RunspaceFactory.CreateRunspace();
rs.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = rs;
ps.AddScript("Add-PSSnapin VeeamPSSnapin");
ps.AddScript("Add-PSSnapin VMware.*");
ps.AddScript("Get-PSSnapin");
try
{
foreach (PSObject result in ps.Invoke())
{
Console.Write(result.ToString());
}
}
catch(Exception e)
{
rs.Close();
}
rs.Close();
}
}
This is the output that I get...
Microsoft.PowerShell.Diagnostics
Microsoft.PowerShell.Core
Microsoft.PowerShell.Utility
Microsoft.PowerShell.Host
Microsoft.PowerShell.Management
Microsoft.PowerShell.Security
Microsoft.WSMan.Management
VMware.VimAutomation.Cloud
VMware.VimAutomation.Core
VMware.VimAutomation.License
VMware.VumAutomation
The Veeam PS snapin is not loading... If I do it manually in PowerShell, it works... So I guess I am asking if anyone has tried to do it the same way as me and successed? Or is there something different about the Veeam snapin that I am missing...
Thanks!
Shane...
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: PowerShell via C# Questions
From my perspective, there are several things you can do:
1) Check whether the corresponding snap-in is loaded, indeed, or it's just not list among others.
2) I don't know for sure, but there has to be some kind of C# log, where you can check and see whether there are any issues with snap-in adding.
3) You can start from the different angle, executing C# commands from the PS. This way, you will be able to use both Veeam PSsnapin and C# commands.
Anyway, it will be appreciated if you provide a little bit more details regarding the task you're trying to achieve.
Thanks.
1) Check whether the corresponding snap-in is loaded, indeed, or it's just not list among others.
2) I don't know for sure, but there has to be some kind of C# log, where you can check and see whether there are any issues with snap-in adding.
3) You can start from the different angle, executing C# commands from the PS. This way, you will be able to use both Veeam PSsnapin and C# commands.
Anyway, it will be appreciated if you provide a little bit more details regarding the task you're trying to achieve.
Thanks.
-
- Novice
- Posts: 3
- Liked: never
- Joined: Feb 20, 2014 4:13 pm
- Full Name: Shane O'Neill
Re: PowerShell via C# Questions
I'm feeling a bit stupid right about now... I figured out what was going wrong with this... I never updated my C# project to x64, it was using x86... So it was creating a 32-bit PS object which was then trying to load a 64-bit PS snapin...
It is working perfectly now...
Thanks!
It is working perfectly now...
Thanks!
-
- VP, Product Management
- Posts: 6035
- Liked: 2860 times
- Joined: Jun 05, 2009 12:57 pm
- Full Name: Tom Sightler
- Contact:
Re: PowerShell via C# Questions
I'm feeling the same because I thought about asking that very question and then decided that was probably too obvious. How is it always those little things that get you.
Who is online
Users browsing this forum: No registered users and 3 guests