Script AzMan Scopes in Hyper-V? <font face=Consolas>Can anyone suggest the way to create AzMan scopes for VMs (I can assign VMs to scopes) with Powershell/WMI/VBScript?</font><hr size="1" align="left" width="25%">tony soper© 2009 Microsoft Corporation. All rights reserved.Tue, 07 Oct 2008 22:05:21 Z3d0888e2-7538-4578-b16c-97b73c8e0f96http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/3d0888e2-7538-4578-b16c-97b73c8e0f96#3d0888e2-7538-4578-b16c-97b73c8e0f96http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/3d0888e2-7538-4578-b16c-97b73c8e0f96#3d0888e2-7538-4578-b16c-97b73c8e0f96tonysoperhttp://social.technet.microsoft.com/Profile/en-US/?user=tonysoperScript AzMan Scopes in Hyper-V? <font face=Consolas>Can anyone suggest the way to create AzMan scopes for VMs (I can assign VMs to scopes) with Powershell/WMI/VBScript?</font><hr size="1" align="left" width="25%">tony soperTue, 07 Oct 2008 20:16:25 Z2008-10-07T20:16:25Zhttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/3d0888e2-7538-4578-b16c-97b73c8e0f96#f6bdbaa3-8022-487e-aef7-bd42a1f38b6ahttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/3d0888e2-7538-4578-b16c-97b73c8e0f96#f6bdbaa3-8022-487e-aef7-bd42a1f38b6atonysoperhttp://social.technet.microsoft.com/Profile/en-US/?user=tonysoperScript AzMan Scopes in Hyper-V?<font face=Consolas>CreateVMInScope<br><br> <p>Option Explicit</p> <p>Dim WMIService<br>Dim VMManagementService<br>Dim VMName<br>Dim VMScope<br>Dim VMSystemGlobalSettingData<br>Dim Result<br>Dim inParameters</p> <p>VMName = InputBox(&quot;Specify the name for the new virtual machine:&quot;)<br>VMScope = InputBox(&quot;Specify the scope to be used for the new virtual machine:&quot;)</p> <p>'Get an instance of the WMI Service in the virtualization namespace.<br>Set WMIService = GetObject(&quot;winmgmts:\\.\root\virtualization&quot;)</p> <p>'Get a VMManagementService object<br>Set VMManagementService = WMIService.ExecQuery(&quot;SELECT * FROM Msvm_VirtualSystemManagementService&quot;).ItemIndex(0)</p> <p>' Initialize the global settings for the VM<br>Set VMSystemGlobalSettingData = WMIService.Get(&quot;Msvm_VirtualSystemGlobalSettingData&quot;).SpawnInstance_()</p> <p>'Set the name and scope<br>VMSystemGlobalSettingData.ElementName = VMName <br>VMSystemGlobalSettingData.ScopeOfResidence = VMScope </p> <p>' Create the VM<br>VMManagementService.DefineVirtualSystem(VMSystemGlobalSettingData.GetText_(1))</p><br></font><hr size="1" align="left" width="25%">tony soperTue, 07 Oct 2008 20:18:21 Z2008-10-07T20:18:21Zhttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/3d0888e2-7538-4578-b16c-97b73c8e0f96#c33b723a-6a13-4f91-86cb-3a1b3c4578bdhttp://social.technet.microsoft.com/Forums/en-US/ITCG/thread/3d0888e2-7538-4578-b16c-97b73c8e0f96#c33b723a-6a13-4f91-86cb-3a1b3c4578bdtonysoperhttp://social.technet.microsoft.com/Profile/en-US/?user=tonysoperScript AzMan Scopes in Hyper-V? After you have created the scopes, you may need these:<br>DisplayVMScopes<br>ClearVMScopes<br>ChangeVMScope<br>***************<br><br> <p style="margin:0in 0in 0pt"><font face=Consolas>DisplayVMScopes<br></font></p><font face=Consolas> <p>Option Explicit<br> <br>Dim WMIService<br>Dim VMList<br>Dim VM<br>Dim VMSystemGlobalSettingData<br>Dim Message</p> <p>'Setup start of message string<br>Message = &quot;Virtual Machines and their scope of residence&quot; &amp; chr(10) _<br>          &amp; &quot;========================================&quot;<br> <br>'Get instance of 'virtualization' WMI service on the local computer<br>Set WMIService = GetObject(&quot;winmgmts:\\.\root\virtualization&quot;)<br> <br>'Get all the MSVM_ComputerSystem object<br>Set VMList = WMIService.ExecQuery(&quot;SELECT * FROM Msvm_ComputerSystem&quot;)<br>    <br>For Each VM In VMList<br>   if VM.Caption = &quot;Virtual Machine&quot; then<br>       Set VMSystemGlobalSettingData = (VM.Associators_(&quot;MSVM_ElementSettingData&quot;, &quot;Msvm_VirtualSystemGlobalSettingData&quot;)).ItemIndex(0) <br>       Message = Message &amp; chr(10) &amp; &quot;VM:       &quot; &amp; VM.ElementName<br>       Message = Message &amp; chr(10) &amp; &quot;Scope:  &quot; &amp; VMSystemGlobalSettingData.ScopeOfResidence<br>       Message = Message &amp; chr(10)<br>    end if<br>Next</p> <p>wscript.echo Message</p> <p style="margin:0in 0in 0pt">**********************<br><br>ClearVMScopes<br><br></p> <p>Option Explicit<br> <br>Dim WMIService<br>Dim VMList<br>Dim VM<br>Dim VMSystemGlobalSettingData<br>Dim VMManagementService<br>Dim Result<br> <br>'Get instance of 'virtualization' WMI service on the local computer<br>Set WMIService = GetObject(&quot;winmgmts:\\.\root\virtualization&quot;)</p> <p>'Get a VMManagementService object<br>Set VMManagementService = WMIService.ExecQuery(&quot;SELECT * FROM Msvm_VirtualSystemManagementService&quot;).ItemIndex(0)<br> <br>'Get all the MSVM_ComputerSystem object<br>Set VMList = WMIService.ExecQuery(&quot;SELECT * FROM Msvm_ComputerSystem&quot;)<br>    <br>For Each VM In VMList<br>   if VM.Caption = &quot;Virtual Machine&quot; then<br>       Set VMSystemGlobalSettingData = (VM.Associators_(&quot;MSVM_ElementSettingData&quot;, &quot;Msvm_VirtualSystemGlobalSettingData&quot;)).ItemIndex(0) <br>       VMSystemGlobalSettingData.ScopeOfResidence = &quot;&quot;<br>       Result = VMManagementService.ModifyVirtualSystem(VM.Path_.Path, VMSystemGlobalSettingData.GetText_(1))<br>    end if<br>Next<br></p></font> <p style="margin:0in 0in 0pt"><font face=Consolas>******************************<br><br>ChangeVMScope<br><br>Option Explicit<br> <br>Dim WMIService<br>Dim VM<br>Dim VMManagementService<br>Dim VMSystemGlobalSettingData<br>Dim VMName<br>Dim VMScope<br>Dim Result<br> <br>'Setup variables for the VM we are looking for, and the scope to assign it to<br>VMName = InputBox(&quot;Specify the virtual machine to change scope on:&quot;)<br>VMScope = InputBox(&quot;Specify the new scope to be used:&quot;)<br> <br>'Get an instance of the WMI Service in the virtualization namespace.<br>Set WMIService = GetObject(&quot;winmgmts:\\.\root\virtualization&quot;)<br> <br>'Get a VMManagementService object<br>Set VMManagementService = WMIService.ExecQuery(&quot;SELECT * FROM Msvm_VirtualSystemManagementService&quot;).ItemIndex(0)<br> <br>'Get the VM object that we want to modify<br>Set VM = (WMIService.ExecQuery(&quot;SELECT * FROM Msvm_ComputerSystem WHERE ElementName='&quot; &amp; VMName &amp; &quot;'&quot;)).ItemIndex(0)<br> <br>'Get the VirtualSystemGlobalSettingsData of the VM we want to modify<br>Set VMSystemGlobalSettingData = (VM.Associators_(&quot;MSVM_ElementSettingData&quot;, &quot;Msvm_VirtualSystemGlobalSettingData&quot;)).ItemIndex(0) <br> <br>'Change the ScopeOfResidence property<br>VMSystemGlobalSettingData.ScopeOfResidence = VMScope<br> <br>'Update the VM with ModifyVirtualSystem<br>Result = VMManagementService.ModifyVirtualSystem(VM.Path_.Path, VMSystemGlobalSettingData.GetText_(1))<br></font></p><hr size="1" align="left" width="25%">tony soperTue, 07 Oct 2008 20:22:59 Z2008-10-07T20:22:59Z