Adding existing VM’s to WAP Subscription using PowerShell

Edit: added Cloud parameter to the script.

Deploying WAP for clients, they start creating new clouds, plans and subscriptions which is great!! But how do they add existing VM’s to new users in WAP?

Easy….. you guessed it…. PowerShell!

So I can’t take the credit here, my sources are found here & here.

Ok, that’s out of the way.. here it is…

Requirements:

  • You must have an existing tenant account
  • That tenant must have an existing VM (I usually just kick off a quick VM deployment in WAP and delete it once done)

I like to use Out-GridView to keep the script portable. Change the name to suit your targeted VMM server and you’re off and racing.

$SCVMMSERVER = Get-SCVMMServer -ComputerName <VMMServer> -ForOnBehalfOf
$VMSource = Get-VM | out-gridview -Title "Select Source VM" -PassThru
 $VMS = Get-SCVirtualMachine | select-object Name,Cloud,Owner | out-gridview -Title "Select Target VMs" -PassThru
 ForEach($VM in $VMS)
 {
 $VM = Get-VM -Name $VM.Name
 $VMNameSource = $VMSource.Name
 $VMInfo = Get-SCVirtualMachine -name $VMNameSource
 $Cloud = $VMInfo.Cloud
 $VMOwner = $VMInfo.owner
 $VMUserRole = $VMInfo.selfserviceuserrole
 Set-SCVirtualMachine –VM $VM –UserRole $VMUserRole –Owner $VMOwner -Cloud $Cloud
 }

What, that’s it? Yep. That’s it 🙂

Enjoy!

Dan

Leave a Reply

Your email address will not be published. Required fields are marked *