As you start working with Azure Pack, you probably realize that you have a lot of existing VM’s that you would like to import into Azure Pack, and by that be able to use them just as you can handle all new ones?
All that’s needed for that, is to set the correct AzurePack user as the owner and SelfServicUuser on that Virtual Machine. And of course, have the machine in the correct “Cloud”.
Here is a small script which will help you out by;
- Asking in a Grid View, which Cloud you would like to import a machine in.
- Ask which user that should be the new owner of this VM.
- Let you pick, which VM from the Cloud you would like to import.
As we have multiple clouds, and users can have multiple subscriptions, I chose to make the script use GridView, to minimize the risk for human errors (typos).
# You have to set your SCVMM server and use -ForOnBehalfOf to make use of SPF.
$SCVMMSERVER = Get-SCVMMServer -ComputerName YOUR.SCVVM.SERVER.FQDN -ForOnBehalfOf
$SCCloud = Get-SCCloud -Name (Get-SCCloud | select Name | Out-GridView -Title "Select Cloud" -PassThru).Name
$SCUser = (Get-SCUserRole | Where-Object Cloud -Match $SCCloud).Name -Replace "_.+","" | Out-GridView -PassThru -Title "Select User"
$vmselfserviceuserrole = Get-SCUserRole | Where-Object Cloud -Match $SCCloud | Where-Object Name -Like $SCUser*
$SCVM = (get-scvirtualmachine ($SCCloud | Get-SCVirtualMachine | select Name | Out-GridView -Title "Select VM" -PassThru).Name)
Set-SCVirtualMachine -VM $SCVM –UserRole $vmselfserviceuserrole –Owner $SCUser
3 thoughts on “Script for importing existing VMs into Azure Pack”
thanks for your post, I got it work, however , I got error when try to go VM Dashboard properties about unable to locate VMMNetowrk properties, do you have idea how to fix? thanks!
Just a quick suggestion : the -Replace “_.+”,”” part when displaying users will remove subscription information from users’ list. This might be good when each user only has a single subscription but when users might have multiple subscriptions assigned that makes impossible to know which subscription you will assign the VM to because script will show the same e-mail address multiple times.
You might want to add a parameter to your script to deal with this, to decide if subscription info will be displayed or not.
Great script, man ! 😉