VMware Cloud Community
madhanSakthi
Contributor
Contributor
Jump to solution

Calling Powercli commands from C#

Hi,

Is there a way to use powercli commands from C# ? .Like how we are specifying the command in Powercli console,

"Connect-VIServer -Server 172.17.21.51 -Protocol https -User user -Password pass -Port 883". is it possible to

write the same command inside c# and connect to the server and perform similar actions like Get-vm, New-VM etc

Thanks,

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Yes, you can create a VM from  template.

In PowerCLI that would be with the New-VM cmdlet, in the API it would be method CloneVM_Task

There is a set of pointers and samples in HowTo: Beginners Advice for using the vSphere APIs in C#

Unfortunately none on the CloneVM_Task


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

5 Replies
madhanSakthi
Contributor
Contributor
Jump to solution

if it possible to connect to vsphere server and perform the actions like create vm, start vm, etc. from C# by any other means, pls suggest that too.

Any example code to connect, create vm would be of great help

Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you already see the vSphere SDK for .NET Developer’s Guide ?

It's old, but the concepts are still (mostly) valid, and it has some samples.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
madhanSakthi
Contributor
Contributor
Jump to solution

HI LUCD,,,Thanks for the link...ya..I was trying the code in the Developer's guide in latest powercli. But, so many changes in new version and it is not helping much.

My main requirement is to create a new VM from a "template". I couldnt find any article explaining how to create new vm from templates.

Is it possible to create vm from template ?

Thanks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, you can create a VM from  template.

In PowerCLI that would be with the New-VM cmdlet, in the API it would be method CloneVM_Task

There is a set of pointers and samples in HowTo: Beginners Advice for using the vSphere APIs in C#

Unfortunately none on the CloneVM_Task


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

madhanSakthi
Contributor
Contributor
Jump to solution

Thanks a lot LucD !!.. I ve explored CloneVM_Task and other similar methods and made a very good progress in my work... Smiley Happy Smiley Happy

0 Kudos