VMware Cloud Community
jasonrobinson
Enthusiast
Enthusiast
Jump to solution

Remote Console URL

Guys,

I need to generate the remote console url for all the vms in a given VC and export them to a txt file. From looking over the url I can see that VC encodes the vm-ID with base64. I dont see any cmdlet that will allow me to convert this string. Does anyone have any suggestions?

Thanks,

Jason

Jason @jrob24
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, I went ahead and wrote a script that will generate the URL without using the PSCX pssnapin.

It only uses some .Net methods, so support should be no problem.

Since there are quite some square brackets in the script, use the attached file.

It shouldn't be too hard to roll this into a function and generate URLs for all your guests Smiley Wink


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

View solution in original post

Reply
0 Kudos
35 Replies
LucD
Leadership
Leadership
Jump to solution

The PS Community Extensions (PSCX) have a pssnapin that contains a ConvertTo-Base64 cmdlet.

Did you already try that one ?


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

Reply
0 Kudos
jasonrobinson
Enthusiast
Enthusiast
Jump to solution

I have not because I didnt think they were fully supported and I hestitate to use them on a production environment.

Jason @jrob24
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

In that case you could use the .Net Convert.ToBase64String Method.

You can call the method like this

$VMidB64 = [http://System.Convert|http://System.Convert]::ToBase64String($VMid)


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

Reply
0 Kudos
jasonrobinson
Enthusiast
Enthusiast
Jump to solution

Ok, I went ahead and installed the PSCX extensions and plan on using them in a testing environment first. Now can someone help me generate the remote console URL and convert it to base64? Thanks in advance.

Jason @jrob24
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, I went ahead and wrote a script that will generate the URL without using the PSCX pssnapin.

It only uses some .Net methods, so support should be no problem.

Since there are quite some square brackets in the script, use the attached file.

It shouldn't be too hard to roll this into a function and generate URLs for all your guests Smiley Wink


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

Reply
0 Kudos
jasonrobinson
Enthusiast
Enthusiast
Jump to solution

Thanks Luc, that was exactly what I was looking for.

Jason @jrob24
Reply
0 Kudos
jasonrobinson
Enthusiast
Enthusiast
Jump to solution

Luc,

I am having one problem and wanted to see if you wouldnt mind assisting me. I am trying to loop through a couple of different VC's and then export to a csv. I have attached the script that I am using. The problem is that the data is being overwritten and not appending to the csv. I dont see an option to append data with Export-CSV and I tried to use Out-File with the -append switch, however the format did not come out correct. Can you help me out? Thanks.

Jason

Jason @jrob24
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Jason, if you place the $report initialisation and export outside the VC loop it should work.


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

jasonrobinson
Enthusiast
Enthusiast
Jump to solution

Ah, that makes sense. Thanks again for your assistance.

Jason @jrob24
Reply
0 Kudos
AS80
Contributor
Contributor
Jump to solution

Luc,

When I try to run this script the output comes as this.. and when i try to access these URL i got page not found

VC

vmName

vmURL

v190tty

IPDT03CNC

v190tty

PSQL01YKF

v190tty

WLQ04YKF

v190tty

TMTX03YKF

v191tty

BDEMO01CNC

v191tty

LSW12CNC

v191tty

MDCT03YKF

I am running this from my computer where I have PowerCli installed and VC is installed on different servers

Can you please help me

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are v190tty and vt191tty the hostnames of your Virtual Centers ?

You have to populate the variable $vcNames (2nd line) with name(s) of your Virtual Center(s).

If you use only 1 VC, you can do this as follows

$vcNames = @("VC01")

That way you force an array with one element.


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

Reply
0 Kudos
AS80
Contributor
Contributor
Jump to solution

This is how my script looks like and it still gets me the URL in this format.. Do I have to run it from the VC server, Do i need to install any plugin.. I am getting the same results again

$report = @()

$vcNames = @("vcb24yyz")

foreach ($vcName in $vcNames){

Connect-VIServer $vcName

  1. Masks for the check-boxes on the generate remote console URL page

$Limit_Remote_Console_Single_Machine = 36

$No_Limit_Remote_Console_Single_Machine = 33

$Limit_Remote_Console_No_Single_Machine = 12

$No_Limit_Remote_Console_No_Single_Machine = 9

$vms = Get-VM

foreach ($vmName in $vms){

  1. Generate the URL

$sdkUrl = "wsUrl=http://localhost/sdk&vmId=VirtualMachine|" + (Get-VM $vmName | Get-View).MoRef.Value + "&ui=" + $Limit_Remote_Console_Single_Machine

$sdkUrlAsc = http://System.Text.Encoding::ASCII.GetBytes($sdkUrl)

$sdkUrlB64 = http://System.Convert::ToBase64String($sdkUrlAsc)

$vmUrl = "https://" + $vcName + "/ui/vmDirect.do?view=" + $sdkUrlB64 + "_"

$row = "" | Select VC, vmName, vmURL

$row.vc = $vcname

$row.vmName = $vmName.Name

$row.vmURL = $vmUrl

$report += $row

}

Disconnect-viserver -Confirm:$false

}

$report | Export-Csv .\vmURL.csv -NoTypeInformation

Thanks for help, I really appreciate it

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I just tried your script and it generates the correct URLs for me.

Can you try the first script in this thread (it's called Generate-remote-console-URL.ps1) ?

It's for one VC and one guest, but I'm curious if you get the same strange URLs.


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

Reply
0 Kudos
AS80
Contributor
Contributor
Jump to solution

The actual Console URL looks like this

https://vcb194yyz/?wsUrl=http://localhost:80/sdk&mo=VirtualMachine|vm-264&inventory=none&tabs=hide

Any idea what I am missing here

Reply
0 Kudos
AS80
Contributor
Contributor
Jump to solution

this is the script which i ran... and i attached the results i got same URL

by the way I am Vpshere does it matters or this script was written for any version

#$vcName = "vcb110yyz"

$vmName = "B01YYZ"

  1. Masks for the check-boxes on the generate remote console URL page

$Limit_Remote_Console_Single_Machine = 36

$No_Limit_Remote_Console_Single_Machine = 33

$Limit_Remote_Console_No_Single_Machine = 12

$No_Limit_Remote_Console_No_Single_Machine = 9

  1. Generate the URL

$sdkUrl = "wsUrl=http://localhost/sdk&vmId=VirtualMachine|" + (Get-VM $vmName | Get-View).MoRef.Value + "&ui=" + $Limit_Remote_Console_Single_Machine

$sdkUrlAsc = http://System.Text.Encoding::ASCII.GetBytes($sdkUrl)

$sdkUrlB64 = http://System.Convert::ToBase64String($sdkUrlAsc)

$vmUrl = "https://" + $vcName + "/ui/vmDirect.do?view=" + $sdkUrlB64 + "_"

$vmUrl

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That looks as if the ASCII.GetBytes and/or Base64 method didn't work.

You sure to have square brackets around "System.Text.Encoding" and "System.Convert" ?

When you copy/paste PowerShell code the forum SW sometimes converts square brackets to a string like "http://System.Text.Encoding".

Are these methods available on the PC where you run the script ?

They are normally included from .Net 1.1 onwards.


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

Reply
0 Kudos
AS80
Contributor
Contributor
Jump to solution

Luc,

This is what I am using.. Can you please look at this one

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Your script works perfectly for me.

Let's get some basic facts:

*) are you running this against VC 2.5 or a vCenter ?

*) are you using PowerShell v1 or v2 ?

*) are you using PowerCLI v4 ?

*) from where do you run the script ? PowerCLI prompt, PowerShell prompt, PowerGui...?

*) on the previous screenshot the name of your VC was missing from the URL.


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

Reply
0 Kudos
AS80
Contributor
Contributor
Jump to solution

Luc,

I am running it against Vcenter server running VCenter version 4

I have Windows Powershell version 1.0

I am using Power Cli version 4.0

I have ran this script from Power CLI and from Power GUI

I hide the VC name...

let me know if this is some thing that is supported

Thanks I really appreciate your response

Reply
0 Kudos