Stellen Sie eine FrageStellen Sie eine Frage
 

BeantwortetScript AzMan Scopes in Hyper-V?

Antworten

  • Dienstag, 7. Oktober 2008 20:18tonysoperMSFTTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet
    CreateVMInScope

    Option Explicit

    Dim WMIService
    Dim VMManagementService
    Dim VMName
    Dim VMScope
    Dim VMSystemGlobalSettingData
    Dim Result
    Dim inParameters

    VMName = InputBox("Specify the name for the new virtual machine:")
    VMScope = InputBox("Specify the scope to be used for the new virtual machine:")

    '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)

    ' Initialize the global settings for the VM
    Set VMSystemGlobalSettingData = WMIService.Get("Msvm_VirtualSystemGlobalSettingData").SpawnInstance_()

    'Set the name and scope
    VMSystemGlobalSettingData.ElementName = VMName
    VMSystemGlobalSettingData.ScopeOfResidence = VMScope

    ' Create the VM
    VMManagementService.DefineVirtualSystem(VMSystemGlobalSettingData.GetText_(1))



    tony soper
    • Als Antwort markierttonysoperMSFTDienstag, 7. Oktober 2008 22:05
    •  
  • Dienstag, 7. Oktober 2008 20:22tonysoperMSFTTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet
    After you have created the scopes, you may need these:
    DisplayVMScopes
    ClearVMScopes
    ChangeVMScope
    ***************

    DisplayVMScopes

    Option Explicit
     
    Dim WMIService
    Dim VMList
    Dim VM
    Dim VMSystemGlobalSettingData
    Dim Message

    'Setup start of message string
    Message = "Virtual Machines and their scope of residence" & chr(10) _
              & "========================================"
     
    'Get instance of 'virtualization' WMI service on the local computer
    Set WMIService = GetObject("winmgmts:\\.\root\virtualization")
     
    'Get all the MSVM_ComputerSystem object
    Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem")
       
    For Each VM In VMList
       if VM.Caption = "Virtual Machine" then
           Set VMSystemGlobalSettingData = (VM.Associators_("MSVM_ElementSettingData", "Msvm_VirtualSystemGlobalSettingData")).ItemIndex(0)
           Message = Message & chr(10) & "VM:       " & VM.ElementName
           Message = Message & chr(10) & "Scope:  " & VMSystemGlobalSettingData.ScopeOfResidence
           Message = Message & chr(10)
        end if
    Next

    wscript.echo Message

    **********************

    ClearVMScopes

    Option Explicit
     
    Dim WMIService
    Dim VMList
    Dim VM
    Dim VMSystemGlobalSettingData
    Dim VMManagementService
    Dim Result
     
    'Get instance of 'virtualization' WMI service on the local computer
    Set WMIService = GetObject("winmgmts:\\.\root\virtualization")

    'Get a VMManagementService object
    Set VMManagementService = WMIService.ExecQuery("SELECT * FROM Msvm_VirtualSystemManagementService").ItemIndex(0)
     
    'Get all the MSVM_ComputerSystem object
    Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem")
       
    For Each VM In VMList
       if VM.Caption = "Virtual Machine" then
           Set VMSystemGlobalSettingData = (VM.Associators_("MSVM_ElementSettingData", "Msvm_VirtualSystemGlobalSettingData")).ItemIndex(0)
           VMSystemGlobalSettingData.ScopeOfResidence = ""
           Result = VMManagementService.ModifyVirtualSystem(VM.Path_.Path, VMSystemGlobalSettingData.GetText_(1))
        end if
    Next

    ******************************

    ChangeVMScope

    Option Explicit
     
    Dim WMIService
    Dim VM
    Dim VMManagementService
    Dim VMSystemGlobalSettingData
    Dim VMName
    Dim VMScope
    Dim Result
     
    'Setup variables for the VM we are looking for, and 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 we want to modify
    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))


    tony soper
    • Als Antwort markierttonysoperMSFTDienstag, 7. Oktober 2008 22:05
    •  

Alle Antworten

  • Dienstag, 7. Oktober 2008 20:18tonysoperMSFTTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet
    CreateVMInScope

    Option Explicit

    Dim WMIService
    Dim VMManagementService
    Dim VMName
    Dim VMScope
    Dim VMSystemGlobalSettingData
    Dim Result
    Dim inParameters

    VMName = InputBox("Specify the name for the new virtual machine:")
    VMScope = InputBox("Specify the scope to be used for the new virtual machine:")

    '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)

    ' Initialize the global settings for the VM
    Set VMSystemGlobalSettingData = WMIService.Get("Msvm_VirtualSystemGlobalSettingData").SpawnInstance_()

    'Set the name and scope
    VMSystemGlobalSettingData.ElementName = VMName
    VMSystemGlobalSettingData.ScopeOfResidence = VMScope

    ' Create the VM
    VMManagementService.DefineVirtualSystem(VMSystemGlobalSettingData.GetText_(1))



    tony soper
    • Als Antwort markierttonysoperMSFTDienstag, 7. Oktober 2008 22:05
    •  
  • Dienstag, 7. Oktober 2008 20:22tonysoperMSFTTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet
    After you have created the scopes, you may need these:
    DisplayVMScopes
    ClearVMScopes
    ChangeVMScope
    ***************

    DisplayVMScopes

    Option Explicit
     
    Dim WMIService
    Dim VMList
    Dim VM
    Dim VMSystemGlobalSettingData
    Dim Message

    'Setup start of message string
    Message = "Virtual Machines and their scope of residence" & chr(10) _
              & "========================================"
     
    'Get instance of 'virtualization' WMI service on the local computer
    Set WMIService = GetObject("winmgmts:\\.\root\virtualization")
     
    'Get all the MSVM_ComputerSystem object
    Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem")
       
    For Each VM In VMList
       if VM.Caption = "Virtual Machine" then
           Set VMSystemGlobalSettingData = (VM.Associators_("MSVM_ElementSettingData", "Msvm_VirtualSystemGlobalSettingData")).ItemIndex(0)
           Message = Message & chr(10) & "VM:       " & VM.ElementName
           Message = Message & chr(10) & "Scope:  " & VMSystemGlobalSettingData.ScopeOfResidence
           Message = Message & chr(10)
        end if
    Next

    wscript.echo Message

    **********************

    ClearVMScopes

    Option Explicit
     
    Dim WMIService
    Dim VMList
    Dim VM
    Dim VMSystemGlobalSettingData
    Dim VMManagementService
    Dim Result
     
    'Get instance of 'virtualization' WMI service on the local computer
    Set WMIService = GetObject("winmgmts:\\.\root\virtualization")

    'Get a VMManagementService object
    Set VMManagementService = WMIService.ExecQuery("SELECT * FROM Msvm_VirtualSystemManagementService").ItemIndex(0)
     
    'Get all the MSVM_ComputerSystem object
    Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem")
       
    For Each VM In VMList
       if VM.Caption = "Virtual Machine" then
           Set VMSystemGlobalSettingData = (VM.Associators_("MSVM_ElementSettingData", "Msvm_VirtualSystemGlobalSettingData")).ItemIndex(0)
           VMSystemGlobalSettingData.ScopeOfResidence = ""
           Result = VMManagementService.ModifyVirtualSystem(VM.Path_.Path, VMSystemGlobalSettingData.GetText_(1))
        end if
    Next

    ******************************

    ChangeVMScope

    Option Explicit
     
    Dim WMIService
    Dim VM
    Dim VMManagementService
    Dim VMSystemGlobalSettingData
    Dim VMName
    Dim VMScope
    Dim Result
     
    'Setup variables for the VM we are looking for, and 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 we want to modify
    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))


    tony soper
    • Als Antwort markierttonysoperMSFTDienstag, 7. Oktober 2008 22:05
    •