In order to delegate management to a subset of the virtual machines running on a Hyper-V server, you must create a new Authorization Manager scope and apply it to the target set of virtual machines before creating a new role, task, and role assignment. You can create the new scope using the Authorization Manager Console. Then, to apply the new scope, you must set the ScopeOfResidence property to the new scope name for each target virtual machine. Because you cannot perform this step using the Authorization Manager Console, you have to use a script to modify each virtual machine ScopeOfResidence property. Following is a sample VBScript that allows you to assign a new scope to a virtual machine.
Option Explicit
Dim WMIService
Dim VMDim VMManagementService
Dim VMSystemGlobalSettingData
Dim VMName
Dim VMScope
Dim Result
'Enter the VM name and the name of the scope to assign it to
VMName = InputBox("Specify the virtual machine to change scope on:")
VMScope = InputBox("Specify the new scope to be used:")
'Get an instance of the WMI Service in the virtualization namespace
Set WMIService=GetObject("winmgmts:\\.\root\virtualization")
'Get a VMManagementService object
Set VMManagementService = WMIService.ExecQuery("SELECT * FROM Msvm_VirtualSystemManagementService").ItemIndex(0)
'Get the VM object that we want to modify
Set VM=(WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE ElementName='" & VMName & "'")).ItemIndex(0)
'Get the VirtualSystemGlobalSettingsData of the VM to be modified
Set VMSystemGlobalSettingData = (VM.Associators_("MSVM_ElementSettingData", "Msvm_VirtualSystemGlobalSettingData")).ItemIndex(0)
'Change the ScopeOfResidence property
VMSystemGlobalSettingData.ScopeOfResidence = VMScope
'Update the VM with ModifyVirtualSystem
Result = VMManagementService.ModifyVirtualSystem(VM.Path_.Path,
VMSystemGlobalSettingData.GetText_(1))