Use Powershell to add the Host to SCVMM from your XenDesktop DDC

Sorry I haven't posted in a while. A case of pneumonia and Kylie had bronchitis so I'm a bit behind.

Here is an interesting bit:
I grabbed some code from and added it to some code scraped out of SCVMM to get something to automate adding a host to SCVMM.

I used Set-myCredential.ps1 to save a credential file:

$user = "xendesktop\administrator"
$file = "c:\scripts\credentials.enc.xml"
$Credential = Get-Credential
$credential.Password | ConvertFrom-SecureString | Set-Content $File

I use the reverse to get the credential and add the host to SCVMM. The idea here is to have an easy way to import a machine running the SCVMM console and add the local host. A renewable or transportable demo or test system or part of an automation script for a cloud based host. You might set up the internal networks to be identical on each physical host and then use the ip address to access the local host.

$user = "xendesktop\administrator"
$file = "c:\scripts\credentials.enc.xml"
$password = Get-Content $File | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential($user,$password)

$VMHostGroup = Get-VMHostGroup -VMMServer localhost | where {$_.Path -eq "All Hosts"}

Add-VMHost -VMMServer localhost -ComputerName "" -Description "" -Credential $Credential -RemoteConnectEnabled $true -VmPaths "" -Reassociate $false -RunAsynchronously -VMHostGroup $VMHostGroup

A cool side effect is that if you do this and the host does not have Hyper-V role it will add it automatically and reboot. Cool or not cool depending on if you expect it.

Thanks for your time, and thanks for hanging out with me here.
Take care,

Desktop Delivery: 
Virtualization Servers and Hosts: 
Microsoft Server Products: 
Powered by Drupal