VMware Cloud Community
LudovicB
Contributor
Contributor

Give the ability to start a VM with a script but without local install of powercli

Hi,

I would like to give the ability to start a VM without using the VC web interface and without installing PowerCli locally.

I gave permissions (Virtual Machine User) to the good folder.

I use this script on a PC with powerCli installed locally : It works fine

Add-PSSnapin VMWare.VimAutomation.Core

Connect-VIServer PBCVMWareVC

$myVMName = 'ZY0272'

$myVM = Get-VM -debug:$False $myVMName

If ($myVM.PowerState -eq 'PoweredOff') { $myVM | Start-VM -debug:$False -RunAsync }

$myVM

I put my user in the Remote Management Users local group of the PC with PowerCli

And went to the PC without PowerCli and then I tried to execute :

Invoke-Command -ComputerName ZH016 -ScriptBlock { Add-PSSnapin VMWare.VimAutomation.Core; Connect-VIServer PBCVMWareVC; $myVMName = 'ZY0272'; $myVMName; $myVM = Get-VM $myVMName; $myVM }

It went to the line $myVMName, well connecting to my VCenter

But nothing append for the Get-VM command.

And nothing append !

Could you help me ?

Is there a friendly way to give the ability to start a VM to a non-IT, just a simple user ...

Thank you,

Ludovic.

0 Kudos
9 Replies
LucD
Leadership
Leadership

Could you include a screenshot of the output you received?

Which PowerCLI version did you install on the remote PC ?


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

0 Kudos
jpsider
Expert
Expert

What about sending the user a link to the "ConsoleURL" ? With proper permissions they will be able to turn the vm on/off, and not have to navigate through the vCenter UI.

0 Kudos
LucD
Leadership
Leadership

AfaikOpen-VMConsoleWindow only works for a powered on VM, meaning you will have to use the VMRC method I guess.

Which would mean that you need at least to install VMRC.


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

0 Kudos
LudovicB
Contributor
Contributor

Hi,

My PowerCli version is 6.0.0.7254 anywhere.

The screenshot on the first PC :

Presse-papier05.jpg

The screenshot on the second PC :

Presse-papier06.jpg

0 Kudos
LucD
Leadership
Leadership

From the version number you gave I deduce you have PowerCLI 6.0 R1 installed.

In PowerCLI 6.0 (R1 and R2) there is a problem when executing specific cmdlets in a remote session.

The Add-PSSnapin is one of them I'm afraid.

Can you go back to PowerCLI 5.8 till this problem is fixed ?


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

0 Kudos
LudovicB
Contributor
Contributor

Hi,

I tried with the 5.8.0-2057893 version of PowerCli and i got the same trouble.

Ludovic.

0 Kudos
LucD
Leadership
Leadership

Can you try the following ?

Start a remote session with Enter-PSSesion to a computer that has PowerCLI 5.8 installed.

In the remote session do a Add-PSSnapin -Name VMware*

Do you get an error ?


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

0 Kudos
LudovicB
Contributor
Contributor

No errors !

if I start with Enter-Session I can have a result for my Get-VM command

So I tried to create a script with $myS = New-PSSession but I block on the same line Get-VM !

It is the same thing with the two versions of PowerCLI.

I notice that the result of the Connect-VISServer is not exactly the same in the two screenshots.

But in the second we can see the line IsConnected : True !

Ludovic.

0 Kudos
LucD
Leadership
Leadership

Ouch, that seems to indicate that the remote session issue was already there in PowerCLI 5.8.

Would a web based PowerShell console be a valid alternative ?


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

0 Kudos