VMware Cloud Community
samselvan
Contributor
Contributor

Is it possible to login to VM via powercli?

I have to run some scripts inside VM after start-VM , I need to login to VM.

One way is i can store my remote desktop credentials details as rdp file and invoke the .rdp file.

Is there any cmdlet available to login to Vm ?

Tags (2)
3 Replies
schepp
Leadership
Leadership

Hi,

do you know the invoke-vmscript cmdlet?     http://www.vmware.com/support/developer/PowerCLI/PowerCLI55/html/Invoke-VMScript.html

Regards

RvdNieuwendijk
Leadership
Leadership

In PowerCLI 5.5 there is a new cmdlet Open-VMConsoleWindow that you can use to open the console of a virtual machine.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
rtunisi
Contributor
Contributor

you can store your credentials in a variable and use invoke-vmscript command to run it into multiple VMs, like

(This will prompt the username/password dialog)

Invoke-VMScript -VM VM01 -ScriptText { commands } -GuestCredential (Get-Credential)

if you want to use it on multiple servers, create some txt file with all vm names and use something like this:

$cred = Get-Credential

gc text.txt | % { Invoke-VMScript -VM $_ -ScriptText { commands } -GuestCredential  $cred }

EDIT: all machines must have VMWare tools installed for this to work