Forum / Remote Desktop Manager - PowerShell Repository

Auto-update VMRC entries with vm-ids

  • Create an Issue
  • Cancel


Hi!


I am messing around with my VMRC entries. I would like to fetch the vm-ids through vcenter and update my RDM entries on demand.


# Fetching VM ID from vCenter
Connect-VIServer -Server virtualcenter.mydomain.tld

# Create a view holding VM Name and Moref
$View_Moref = Get-View -ViewType VirtualMachine | Select -Property Name, @{N='Moref';E={$_.Moref.Value}};

# Get ID for the VMs
$View_Moref | Where Name -eq 'mytestvm' | Select -Property Moref

My problem is creating the RDM entry:

# Working example for getting the VMid:
Get-RDMSession -Name "VMRC" -Group "MY_COMPANY\COUNTRY\CITY\Server\internal\FUNCTION\DOMAIN\HOSTNAME" | Select-Object -ExpandProperty AddOn | Select-Object -ExpandProperty Properties | Select-Xml -XPath "//VmrcConfiguration" | Select-Object -ExpandProperty Node | Select-Object -ExpandProperty VMid

I cannot edit the ID above, tried different methods:

- Exporting, editing, importing doesn't work, because the XML section containing the info is encrypted, like:

...

<AddOn>
<AddOnVersion>2019.1.38.0</AddOnVersion>
<Properties>hZBNSwMxEIbvgv9hyb3JbosIJU0pgniwR5Z2Dk9uJdM0FCG8OGdbxlW3V/J48+9U8xnOyYk6bCmuIFXF9wI...=</Properties>
</AddOn>

...


I also tried to manually edit the exported file with unencrypted content, but import fails then:

<?xml version="1.0"?>
<VmrcConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AuthPassthrough>false</AuthPassthrough>
<Fullsreen>false</Fullsreen>
<Hostname>virtualcenter.mydomain.tld</Hostname>
<VMid>vm-1031752</VMid>
<VMName>vm-1031752</VMName>
</VmrcConfiguration>

- I also tried to manipluate the object with PS, bu cannot write it back:

[Xml] $Xml = New-Object XML
$XmlContent = Get-RDMSession -Name "VMRC" -Group "MY_COMPANY\COUNTRY\CITY\Server\internal\FUNCTION\DOMAIN\HOSTNAME" | Select-Object -ExpandProperty AddOn | Select-Object -ExpandProperty Properties
$Xml.LoadXml($XmlContent)
$Element = $Xml.SelectSingleNode("//VmrcConfiguration"wink
$Element.VMid = 'Test'


And Set-RDMSessionProperty didn't get me anywhere:
Set-RDMSessionProperty -ID "{25719ea2-e1b6-4a85-9998-f7a5d212763e}" -Path "Addon" -Property "Properties" -Value 'Test'
Set-RDMSessionProperty -ID "{25719ea2-e1b6-4a85-9998-f7a5d212763e}" -Path "VmrcConfiguration" -Property "VMid" -Value 'Test'

=> Always finds not path or property

Any help on this is appreciated!

Thanks and best regards

Alex

Clock2 mths

Hello,

I've been searching for quite some time now for the solution of your issue, and I'm quite at the same point as you...
I Will keep digging, but I had a flash and I'm wondering if it would suit your need; It may seem out of the box, but have you looked into the synchronizer? This will keep your entries up to date...

Please let me know! As I mentioned, I'll keep trying.

Best regards,



Alex Belisle

signaturesignature

Clock2 mths


Hi,


thanks for the reply!


I looked at the synchronizer: It also uses PowerCLI. So there must be code available for updating the entries. I suppose the devs should know it.


The Synchronizer itself is nice, but our VMware environment differs from by RDM environment (other folder structure, etc.). So this is unfortunately no solution to my problem.


I also work with a lot of templates, for example for a new Linux Server, it automatically creates a server folder. Structure is as follows:


Folder: Domain
Name: <some_domain_name>
Domain: $DOMAIN_NAME$

Folder: Server (Subfolder of the domain)
Name: <hostname>
Host: $COMPUTER_NAME$.$DOMAIN_NAME$

And the template creates different sessions under the Server folder, using RDM variables, e.g.:

Session Name: SSH
Host: $COMPUTER_HOST$
And different other settings like: Keep alive, etc.

Session Name: WinSCP
Host: $COMPUTER_HOST$
Path: /home/%USERNAME%
Local path: %USERPROFILE%\Downloads
...

Session Name: VMRC
Server: <FQDN of our vcenter>
VM ID: <to be fetched by self written PowerCLI wink>

I use this highly variable template concept of RDM for all types of connections. So if a new server is added, you only got to change the name on create entry by template dialogue and all subconnections directly work due to the use of RDM variables.


I also got templates creating ESXi Servers for different manufacturers with prefilled RSA session like iDRAC, iRMC and so on... This is really handy and using the synchronizer would conflict with that concept..

Best Regards

Alex

Clock2 mths

Hello,

I see...
I'm not the most skilled with Powershell, so you'll have to do a part on your own, but I realized that you could replace the whole content of the "Properties" property...

$s = Get-RDMSession -Name "VMRCEntry" ;
$props = $s.AddOn.Properties ;
$props;

<?xml version="1.0"?>
<VmrcConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AuthPassthrough>false</AuthPassthrough>
<Fullsreen>false</Fullsreen>
<Hostname>VMRCEntry</Hostname>
<UserName>someusername</UserName>
<VMid>toto</VMid>
<VMName>toto</VMName>
</VmrcConfiguration>


$props = '<?xml version="1.0"?>
<VmrcConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AuthPassthrough>false</AuthPassthrough>
<Fullsreen>false</Fullsreen>
<Hostname>VMRCEntry</Hostname>
<UserName>someusername</UserName>
<VMid>NEWVMID</VMid>
<VMName>NEWVMNAME</VMName>
</VmrcConfiguration>';

$s.AddOn.Properties = $props

Set-RDMSession $s;

Thanks for letting us know if this helps.


Best regards,



Alex Belisle

signaturesignature

Clock2 mths


Hi Alexandre,

many thanks for the snippet!


Just wanted to let you know: It works!

1st class support! smile

Best Regards

Alex

Clock2 mths

Hello!

Thanks a lot for the good words, much appreciated.
Glad I could help!


Best regards,



Alex Belisle

signaturesignature

Clock2 mths