VMware Cloud Community
meson3902
Contributor
Contributor

Feature Suggestion: Launch a console session from powershell

I just started playing with the toolkit, but I think it would be a awesome thing if you could open a console session from powershell. Obviously you would have to have the viclient installed, but to execute something like "get-vm "MyServer" | launch-console" would be awesome.

mark

Reply
0 Kudos
4 Replies
sradnidge
Enthusiast
Enthusiast

I second that request! Yes it completely flies in the face of automation and all that, but would be a nice to have so support guys dont need to fire up VC for an individual VM problem.

Reply
0 Kudos
admin
Immortal
Immortal

This is a good idea and we'll examine it more closely.

In the meantime, can anyone try this script to see if it works in your environment:

function launch-console

{

while ($input.movenext()) {

$vm = $input.Current

$hostName = $vm.host.name

$pattern = "VirtualMachine-(?<ID>.+)"

$vm.ID -match $pattern >$null

$mor = $matches.ID

$unEncoded = "wsUrl=http://localhost:8085&vmId=VirtualMachine|$mor&ui=9"

$encoded = http://System.Convert::ToBase64String(http://System.Text.Encoding::UTF8.GetBytes($unEncoded))

$url = "[https://$hostName/ui/vmDirect.do?view|https://$hostname/ui/vmDirect.do?view]=" + $encoded + "_"

$browser = new-object -com internetexplorer.application

$browser.navigate2($url)

$browser.visible = 1

}

}

Use it like get-vm myvm | launch-console

This just launches a browser to web access, and requires a separate login. It seems to work for me, provided the ESX server is not managed by VC Smiley Sad I'd be interested to know if anyone else has any luck with it.

Reply
0 Kudos
halr9000
Commander
Commander

47# Get-VM hellcat* | launch-console

The '-match' operator failed: parsing "VirtualMachine-(?.+)" - Unrecognized grouping construct..

At C:\DOCUME1\HROTTE1\LOCALS~1\Temp\Untitled38.ps1:7 char:15

+ $vm.ID -match <<<< $pattern >$null

The term 'http://System.Convert::ToBase64String' is not recognized as a cmdlet, function, operable pro

gram, or script file. Verify the term and try again.

At C:\DOCUME1\HROTTE1\LOCALS~1\Temp\Untitled38.ps1:10 char:50

+ $encoded = http://System.Convert::ToBase64String <<<< (http://System.Text.Encoding::UTF8.GetBytes($

unEncoded))

Aside from that, it worked perfectly! Smiley Happy

It did open the web VI client, but not a console.

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
admin
Immortal
Immortal

Maybe a copy-and-paste issue? There should be an &lt;ID&gt; in the regular expression.

"VirtualMachine-(?&lt;ID&gt;.+)"

Also, I just got word from our architect that we had this functionality in an early prototype, not sure why it was taken out 😕

Reply
0 Kudos