blog.powershell.no

On Windows PowerShell and other admin-related topics

Automate a task in System Center Virtual Machine Manager 2012 based on the “View Script” button

System Center Virtual Machine Manager has since the beginning had excellent automation capabilities in form of Windows PowerShell. In fact, everything that is performed in the SC VMM Console generates a PowerShell command which is being invoked as a job. A very useful feature in the SC VMM Console is the “View Script” button, which shows you the actual PowerShell commands that is being run. To show you how you can leverage this functionality, I am going to show you how I used it to automate one part of a new deployment.

 

Provisioning Logical Networks in System Center Virtual Machine Manager 2012

In System Center Virtual Machine Manager 2012 there is a concept called Logical Networks, which is defined as part of the Fabric. You can read more about Logical Networks in this article by the SC VMM team. Step-by-step guidance on how to create and assign a logical network is available in this TechNet Wiki guide by Microsoft MVP Kristian Nese.

What I want to show you in this article is how you in an easy manner can automate the process of creating and assigning virtual networks. I recently had to provision close to 100 logical networks in a new deployment, and as you can read in the mentioned articles I first needed to create the Logical Networks and then go to the Properties of every virtualization host and assign the correct Logical Network to the correct physical NIC.

In my scenario that would mean more than 1000 mouse clicks if doing the task manually. Next I will show you how to automate the creation and assignment of logical networks.

 

Create the Logical Network

Start the “Create Logical Network” wizard from the Fabric pane in VMM:

image

Creating a Network Site is not mandatory, but this is something I needed in my scenario:

image

Click on the “View Script” button on the Summary page (click Cancel in the wizard afterwards):

image

 

You will be presented with a PowerShell script in a Notepad window. This is the script I got:

$logicalNetwork = New-SCLogicalNetwork -Name "Backend"

$allHostGroups = @()
$allHostGroups += Get-SCVMHostGroup -ID "0e3ba228-a059-46be-aa41-2f5cf0f4b96e"
$allSubnetVlan = @()
$allSubnetVlan += New-SCSubnetVLan -VLanID 0

New-SCLogicalNetworkDefinition -Name "Oslo" -LogicalNetwork $logicalNetwork -VMHostGroup $allHostGroups -SubnetVLan $allSubnetVlan -RunAsynchronously

This above script is the what I will use as the template for my new Logical Network provisioning script. A common approach for creating multiple items is using a foreach loop, but first we need some data which the loop will iterate over. Ìf you have all your Logical Networks defined in an Excel spreadsheet, which was the case for me, you can save the spreadsheet as a comma-separated file and use that as the data source in the script. In PowerShell it is also possible to use a broad number of data sources, for example a SQL database.

After creating a CSV-file I customized the column headers in the file, which will serve as the property names for the imported objects. Here is a sample CSV-file from my lab environment:

Name,Description,HostGroup,VlanID,Site,VMHostAdapterName

Backend,"This is the corporate backend network","All Hosts",0,Oslo,Trunk

As you can see in my customized script there is not very much that is changed:

$networks = Import-Csv -Path C:\Import\VMM_logical_networks.csv

foreach ($network in $networks) {

$logicalNetwork = New-SCLogicalNetwork -Name $network.Name -Description $network.Description

$allHostGroups = @()
$allHostGroups += Get-SCVMHostGroup -Name $network.HostGroup
$allSubnetVlan = @()
$allSubnetVlan += New-SCSubnetVLan -VlanID $network.VlanID

New-SCLogicalNetworkDefinition -Name $network.Site -LogicalNetwork $logicalNetwork -VMHostGroup $allHostGroups -SubnetVLan $allSubnetVlan -RunAsynchronously
}

A brief overview of the changes:

  • On the first line we import the contents of the CSV-file using the Import-Csv cmdlet.
  • Next we iterate over each entry in the CSV-file by using a foreach loop from line 3 to 13. This means that line 4 to 12 will be repeated for every line in the CSV-file.
  • The last customization is made to the parameters of the cmdlets in the script. For example the Name property of New-SCLogicalNetwork is the value ($network.Name) of the Name property of the imported CSV objects.

 

Assigning the Logical Network

The final task is to assign the Logical Networks we created to the correct physical NICs of the virtualization hosts. Again we start by doing the task in the SC VMM Console:

Go into the Properties dialog of one of the virtualization hosts, select Hardware and then select a NIC.

Press the check box of two or more Virtual Networks, and the click the “View Script” button (click Cancel in the Properties dialog afterwards):

image

We can see that the generated script is a bit more complicated than the previous one:

$vmHost = Get-SCVMHost -ID "82b7c0f3-ed2e-4dcc-8b05-40765dba712e" -ComputerName "hpv-jr-02"

$vmHostNetworkAdapter = Get-SCVMHostNetworkAdapter -Name "Broadcom NetXtreme Gigabit Ethernet" -VMHost $vmHost

# Backend
$logicalNetwork = Get-SCLogicalNetwork -ID "b036b32a-8139-4b0e-babc-cda1e98ef2e7"
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork -JobGroup "4af63cdf-ea00-4647-b554-cc7167070f33"

# LAN
$logicalNetwork = Get-SCLogicalNetwork -ID "292c0075-f81d-4af9-81f5-c775c5bcf90a"
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork -JobGroup "4af63cdf-ea00-4647-b554-cc7167070f33"

Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -Description "" -JobGroup "4af63cdf-ea00-4647-b554-cc7167070f33" -VLanMode "Access" -AvailableForPlacement $true -UsedForManagement $true


Set-SCVMHost -VMHost $vmHost -JobGroup "4af63cdf-ea00-4647-b554-cc7167070f33" -RunAsynchronously

We will continue to use the same CSV-file as we did when creating the logical networks. You might have noticed that there was one column in the CSV-file we did not use in the first script: VMHostAdapterName. This is a property which will be used to assign the logical networks to a physical NIC on a virtualization host, based on the connection name of the network adapter. For example, I have renamed a network adapter from “Local Area Connection” to “Trunk #1”. In this case the VMHostAdapterName in the CSV-file should be “Trunk #1” for the Virtual Networks which is mapped to this physical NIC. This network adapter is configured in trunk mode, which means it is assigned multiple VLANs and thus may contain multiple Virtual Networks.

This way of performing the mapping between a physical NIC and a Virtual Network is a design decision I took when creating the script, although you may choose to do the mapping based on other properties, such as the IP-address range of the NIC. Since the environment I was working with had a consistent naming convention for the virtualization host network adapters I found this to be the most appropriate way of doing the mapping.

Before the walkthrough, I will first show you the customized version of the script the VMM Console generated:

$vmhosts = Get-SCVMHost
$networks = Import-Csv -Path C:\Import\VMM_logical_networks.csv

foreach ($vmhost in $vmhosts) {

# Create a Job Group ID
$JobGroupID = [Guid]::NewGuid().ToString()

foreach ($network in $networks) {

$vmHostNetworkAdapter = Get-SCVMHostNetworkAdapter -VMHost $vmhost | Where-Object {($_.LogicalNetworks | Select-Object -ExpandProperty Name) -contains $network.VMHostAdapterName}

if ($vmHostNetworkAdapter) {

$logicalNetwork = Get-SCLogicalNetwork -Name $network.name

Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork -JobGroup $JobGroupID
        }
    }

Set-SCVMHost -VMHost $vmhost -JobGroup $JobGroupID -RunAsynchronously

}

A brief overview of the changes:

  • On the first line we retrieve the virtualization hosts we want to iterate over. You may choose to limit the scope to a specific host group by using the –VMHostGroup parameter.
  • On the second line we import the contents of the CSV-file like we did in the previous script
  • On line 4 to 24 we create a foreach loop to iterate over all the virtualization hosts we initiated in the $vmhosts variable
  • The next thing we do is creating a job group (a GUID), which will make VMM perform all the following changes in a single job. This means that a single job will be run for each virtualization host when adding 100 Virtual Networks, instead of 100 jobs for each virtualization host. The concept of using Job Groups is described in this article in the VMM 2012 documentation on Microsoft TechNet.
  • On line 9-19 we iterate over all of the virtual networks in the CSV-file, and try to find a network adapter with a name equal to the VMHostAdapterName property of the Virtual Network defiend in the CSV-file.
  • Next, an if statement is used to determine if a network adapter was found. If the statement is evaluated to $true the actual change is being committed to the network adapter (this is the same as ticking the checkbox in the dialog box in the screenshot above).
  • When the inner foreach loop is finished the job will be commited by the command on line 21.
  • The same steps will be repeated until the outer foreach loop is finished.

The last recommendation I want to provide is to copy the script generated by the “View Script” button to a PowerShell editor like the Windows PowerShell ISE:

image

As you can see the script in the above screenshot is much easier to read than the following due to features such as syntax coloring and brace matching:

image

 

Resources

Overview of Scripting in VMM

Getting Started with Virtual Machine Manager

System Center: Virtual Machine Manager Engineering Team Blog

Advertisements

April 17, 2012 Posted by | Scripting, System Center Virtual Machine Manager, Virtualization, Windows PowerShell | | 4 Comments

How to configure AntiAffinityClassNames in Failover Clustering using Windows PowerShell

AntiAffinityClassNames is a cluster group property in Windows Failover Clustering used to identify cluster groups that should not be hosted on the same node. When working with clustered Hyper-V environments there is a 1:1 relationship between a cluster group and a virtual machine, and thus we can configure Anti-Affinity for virtual machines using the AntiAffinityClassNames property. For more information, see the links in the resource section in the bottom of the article.

What I want to show in this article is how to configure the AntiAffinityClassNames property using PowerShell. Most articles I have seen in regards to AntiAffinityClassNames covers how to use cluster.exe to configure the property, and since the cluster.exe was deprecated in Windows Server 2008 R2 (it`s still available as a deprecated command) it might be a good idea to learn how to configure this using the new Failover Clustering PowerShell module. In addition you also get other benefits available in PowerShell such as pipelining, export/import to/from different data sources, grouping and so on.

AntiAffinityClassNames is a property of a cluster group, but before we configure the property we need to look at what type it is. We can do this by piping the output of Get-ClusterGroup to the Get-Member cmdlet:

image

We can see in the definition of the property that it is a System.Collections.Specialized.StringCollection type. This means we can not just pass a text string as the property value, we need to create a object of the correct type. The reason this property is not just a System.String (text string) is that a Cluster Group can have more than one AntiAffinityClassNames values. System.Collections.Specialized.StringCollection has a method called Add which can be used to to add values to the collection. Here is a complete example on how to create such an object, add a couple of values to it and at the end assign it to the AntiAffinityClassNames property of a cluster group:

$value = New-Object System.Collections.Specialized.StringCollection
$value.Add("Domain Controllers")
$value.Add("Infrastructure Server Group")
(Get-ClusterGroup "SCVMM SRV01 Resources").AntiAffinityClassNames = $value

Note that this will overwrite any existing values. As we can see it is not very hard to configure a new value, but it might be harder if you want to preserve existing values remove single items of the existing value and so on. In order to make this easier I have created a PowerShell module which contains 3 script cmdlets for managing AntiAffinityClassNames:

image

As you can see in the cmdlet help there is support for pipeline input, which makes it possible to configure the AntiAffinityClassNames values based on input such as a CSV-file:

image

I have also provided examples for the script cmdlets:

image

 

Installing the AntiAffinityClassNames module

Download and unzip AntiAffinityClassNames.zip in the following location: %userprofile%\Documents\WindowsPowerShell\Modules\AntiAffinityClassNames

Alternatively you may save the module in any of the folders in the $Env:PSMODULEPATH variable or import the module from a custom path (Import-Module <path>\AntiAffinityClassNames). Here is some more examples to get you started:

# Import the module
Import-Module AntiAffinityClassNames

# Example usage of the Get-AntiAffinityClassNames script cmdlet

Get-AntiAffinityClassNames -Cluster cluster01.domain.local

Get-AntiAffinityClassNames -Cluster cluster01.domain.local -ClusterGroup "SC VMM SRV01 Resources"

Get-AntiAffinityClassNames -Cluster cluster01.domain.local | Export-Csv -Path c:\temp\AntiAffinityClassNames_cluster01.csv -NoTypeInformation

# Example usage of the Set-AntiAffinityClassNames script cmdlet

Set-AntiAffinityClassNames -Cluster cluster01.domain.local -ClusterGroup "SC VMM SRV01 Resources" -Value "Domain Controllers"

Set-AntiAffinityClassNames -Cluster cluster01.domain.local -ClusterGroup "SC VMM SRV01 Resources" -Value "Domain Controllers" -Keep

Set-AntiAffinityClassNames -Cluster cluster01.domain.local -ClusterGroup "SC VMM SRV01 Resources" -Value "Domain Controllers" -Verbose

# Example usage of the Remove-AntiAffinityClassNames script cmdlet

Remove-AntiAffinityClassNames -Cluster cluster01.domain.local -ClusterGroup "SC VMM SRV01 Resources" -Clear

Remove-AntiAffinityClassNames -Cluster cluster01.domain.local -ClusterGroup "SC VMM SRV01 Resources" -Value "Domain Controllers"

Remove-AntiAffinityClassNames -Cluster cluster01.domain.local -ClusterGroup "SC VMM SRV01 Resources" -Value "Domain Controllers" -Verbose

 

Resources

MSDN: AntiAffinityClassNames

Failover behavior on clusters of three or more nodes

Understanding Hyper-V Virtual Machine (VM) Failover Policies

Private Cloud: Configuring anti-affinity between VMs on Hyper-V 2008 R2 SP1 and VMM 2012

How to automatically avoid running Exchange VMs on the same Hyper-V server after a host failure

Get started with the Failover Clustering PowerShell-module

Enable Persistent Mode for Cluster Resource Groups using the PowerShell Failover Clustering module

February 23, 2012 Posted by | Failover Clustering, Hyper-V R2, Virtualization, Windows PowerShell, Windows Server 2008 R2 | , | Leave a comment

Hyper-V: How to unbind a physical NIC from a Virtual Switch using WMI and PowerShell

If you`re not already familiar with networking in Microsoft Hyper-V I would recommend you to have a look at this whitepaper from Microsoft, which described how networking works in Hyper-V.

The following solution will describe a problem which might occur when configuring virtual networks in Hyper-V. Consider the following scenario:

  • You`re about to configure a new external virtual network in Hyper-V using Hyper-V Manager remotely from another computer. This is a common scenario when working with the Core edition of Windows Server 2008/2008 R2.
  • When selecting the physical NIC to bind to the new virtual network, you choose the adapter which you are remotely connecting to the Hyper-V host through.

What happens in this scenario is that the Virtual Switch Management Service is binding the external Ethernet port for the selected NIC to the Microsoft Windows Virtualization network subsystem. What normally should happen next is that the converted Ethernet port should be bound to the new virtual switch you are creating. However, this never happens since the NIC you are remotely managing the Hyper-V host through is no longer available in the parent operating system. This leaves the NIC in an “orphaned” state, since you cannot use the NIC in the parent operating system, and it`s not in use by any virtual networks.

To resolve this issue, whether using the full GUI version or the Core version of Windows Server, you need to manually unbind the the Ethernet port. There is an UnbindExternalEthernetPort available on the Msvm_VirtualSwitchManagementService WMI class, which is fully documented in this article on MSDN.

To invoke the WMI method we can use Windows PowerShell. To ease the procedure I`ve created a PowerShell function you can use if you ever come into the need for manually unbinding an external Ethernet port in Hyper-V:

 

Function Select-List
{
    Param   ([Parameter(Mandatory=$true  ,valueFromPipeline=$true )]$InputObject, 
             [Parameter(Mandatory=$true)]$Property)

    begin   { $i= @()  }
    process { $i += $inputobject  }
    end     { if ($i.count -eq 1) {$i[0]} elseif ($i.count -gt 1) {
                  $Global:counter=-1
                  $Property=@(@{Label=“ID”; Expression={ ($global:Counter++) }}) + $Property
                  format-table -inputObject $i -autosize -property $Property | out-host
                 $Response = Read-Host “Select NIC to unbind”
                  if ($response -gt “”) { 
                        $I[$response] 
                  }
              }
            }
}

function Remove-HVExternalEthernetPort {

$ExternalEthernetPort = Get-WMIObject -class “Msvm_ExternalEthernetPort” -namespace “root\virtualization” | Select-List -Property name

$HVSwitchObj = Get-WMIObject -class “MSVM_VirtualSwitchManagementService” -namespace “root\virtualization”

if ($ExternalEthernetPort) {
$HVSwitchObj.UnbindExternalEthernetPort()
}
else {
throw “An error occured. Choose a valid ExternalEthernetPort from the provided list”
}

}

Note: The Select-List function is a modified version of the Select-List function available in the PowerShell Management Library for Hyper-V available on CodePlex (see link below).

You can either paste the function into a PowerShell session or save it into ps1-file and dot source it. When done you can invoke the function like this:

image

When you`ve entered the index number for the NIC you want to remove, a return value of 0 indicates the operation succeeded. Any other value indicates an error (look at the previous mentioned MSDN-article for more information).

 

More resources on managing Hyper-V using PowerShell

PowerShell Management Library for Hyper-V – this is an excellent PowerShell module for managing Hyper-V available on CodePlex

System Center Virtual Machine Manager 2012: Scripting

System Center Virtual Machine Manager 2008 R2: Scripting

Hyper-V WMI Using PowerShell Scripts

Script: Determining Virtual Switch Type Under Hyper-V

August 30, 2011 Posted by | Hyper-V, Hyper-V R2, Scripting, Virtualization, Windows PowerShell | , , | 1 Comment

Getting starting with Cisco UCS PowerShell Toolkit

Cisco – widely known as a networking infrastructure vendor – entered the blade server market in 2009. Their offering is called Unified Computing System, described by Gartner as a fabric-enabled, enterprise-class platform with good integration of networking, virtualization, management tools and storage. On the 2011 Gartner Magic Quadrant for Blade Servers they`re defined as a visionary vendor, and it will be interesting to see if they can challenge the 3 leaders Dell, IBM and HP.

The Cisco Unified Computing System is quite different from traditional blade systems, in that the server profiles (so called service profiles) is independent from the physical blade servers. An example to describe what this means is that a physical blade server might fail and be replaced, while the server profile keeps unique ID`s like MAC addresses, World Wide Names (WWN`s) and so on. If using boot from SAN rather than local disk drives, physical interaction is not required to get the system back online if a spare blade server is available.

 

The UCS core components

  • Blade Chassis – Blade server enclosure
  • Cisco UCS Manager – Embedded into the Fabric Interconnect. Provides management capabilities
  • Cisco UCS fabric interconnect – Provides networking (Ethernet/Fibre Channel) and management for connected blades and chassis`
  • Fabric Extenders – Provides connection between the interconnect fabric and the blade enclosures

A photo showing the Cisco Unified Computing System architecture is available here (cisco.com). In regards of management, all aspects of Cisco UCS can be managed through an XML API. This makes it possible for 3rd parties to offer management solutions, and integration with other products. An example of a 3rd party product is the Cisco UCS Iphone/Ipad application for managing and monitoring the system. Links for more information on the management model and the XML API is available in the resources section in the bottom of this article.

 

Cisco UCS PowerShell Toolkit

Based on a customer request from an early adaptor, Cisco provided PowerShell support for managing their UCS product through the XMP API. With the Microsoft automation strategy in mind, this was an excellent choice. It will make integration into products like System Center Orchestrator (formerly Opalis) very easy, and the also make the product attractive for enterprises. The PowerShell administration tool is available as a module part of the Cisco UCS PowerShell Toolkit.

A great way to learn using the Cisco UCS PowerShell Toolkit is downloading the Cisco UCS Emulator. This is a virtual machine image which can be imported into VMware Player or VirtualBox. When the VM is up and running you can access both the UCS Manager (http URL is shown when the VM has started) and the XML API. A great feature is that you can import the configuration from a production UCS to simulate administration changes in a lab environment.

Next, you can download the latest versions of both the Cisco UCS PowerShell Toolkit (aka UCSMPowerTool) and the PowerShell Toolkit User Guide from this website.

The installer will by default put the files in %programfiles%\Cisco\UCSMPowerToolkit:

image

CiscoUCSPS.dll is the assembly which can be imported as a module in Windows PowerShell 2.0 and later. You can either double-click LaunchUCSPS.bat or invoke StartUCSPS.ps1 from an existing PowerShell session to get started. Alternatively you can use Import-Module from an existing PowerShell session like this:
Import-Module “C:\Program Files (x86)\Cisco\UCSMPowerToolkit\CiscoUCSPS.dll”

I would suggest rather than installing to the Program Files folder (which requires administrative privileges), that Cisco generates a module manifest and install the module to the default PowerShell module directory (C:\Users\<username>\Documents\WindowsPowerShell\Modules).

When the module is imported we can use Get-Command with the –Module parameter to list all command inside the CiscoUCSPS module:

image

The current version of the module contains 149 cmdlets, so all commands are not shown in the above screenshot.

The first thing we need to do is connect to an instance of the UCS Manager. If using the Cisco UCS Emulator you can view the management  IP address when the virtual machine has started:

image

We then use the Connect-UCSM cmdlet to connect to the UCS Manager:

image

The default credentials for the UCS Emulator is config/config.

Next we can start exploring cmdlets like Get-Blade and Get-Vlan. Note that by default the cmdlets outputs a lot of information for each object, so I`ve picked out a few properties to show using Format-Table:

image

Going further it`s easy to automate things like adding VLAN and assigning it to a vNIC template:

image

 

Although the PowerShell coverage isn`t 100% yet, it`s possible to administer all aspect of the UCS directly through the XML API from PowerShell using the Invoke-XmlCommand cmdlet.

 

Resources

Cisco Unified Computing

A Platform Built for Server Virtualization: Cisco Unified Computing System

Cisco Unified Computing Forums

Automating Cisco UCS Management with Windows PowerShell

PowerScripting Podcast – Josh Heller from Cisco on UCS and PowerShell

Cisco UCS Manager XML API Programmer’s Guide

Cisco UCS Manager API Management Information Model

Cisco Developer Network: Unified Computing

Managing your Cisco UCS from an iPhone or iPad

July 23, 2011 Posted by | Scripting, Virtualization, Windows PowerShell | , , | 2 Comments

System Center Virtual Machine Manager 2008 and PowerShell

I`ve been playing around with System Center VMM 2008 lately, and I really like “View Script”-button:

new_vm_demo

Clicking on the button you get a text-file containing the script which is being run when you press “Finish”. (Almost the same functionality in Exchange 2007, the difference is that you must press Ctrl + C rather than a button to copy the script/command being run in the Exchange Management Console).

Sample textfile-output:

# ------------------------------------------------------------------------------ # New Virtual Machine Script # ------------------------------------------------------------------------------ # Script generated on 18. desember 2008 18:46:03 by Virtual Machine Manager # # For additional help on cmdlet usage, type get-help <cmdlet name> # ------------------------------------------------------------------------------ New-VirtualNetworkAdapter -VMMServer localhost -JobGroup 6928344f-7732-4e1b-b852-15cf0288cd2f -PhysicalAddressType Dynamic -VLanEnabled $false New-VirtualDVDDrive -VMMServer localhost -JobGroup 6928344f-7732-4e1b-b852-15cf0288cd2f -Bus 1 -LUN 0 $CPUType = Get-CPUType -VMMServer localhost | where {$_.Name -eq "1.20 GHz Athlon MP"} New-HardwareProfile -VMMServer localhost -Owner "RBK\jer" -CPUType $CPUType -Name "Profiledb3743da-b115-4c6b-bab5-6cbf89fde1ad" -Description "Profile used to create a VM/Template" -CPUCount 1 -MemoryMB 512 -RelativeWeight 100 -HighlyAvailable $false -NumLock $false -BootOrder "CD", "IdeHardDrive", "PxeBoot", "Floppy" -LimitCPUFunctionality $false -JobGroup 6928344f-7732-4e1b-b852-15cf0288cd2f New-VirtualDiskDrive -VMMServer localhost -IDE -Bus 0 -LUN 0 -JobGroup 6928344f-7732-4e1b-b852-15cf0288cd2f -Size 40960 -Dynamic -Filename "Demo-01_disk_1" $VMHost = Get-VMHost -VMMServer localhost | where {$_.Name -eq "HYPER-V-JR.rbk.ad"} $HardwareProfile = Get-HardwareProfile -VMMServer localhost | where {$_.Name -eq "Profiledb3743da-b115-4c6b-bab5-6cbf89fde1ad"} $OperatingSystem = Get-OperatingSystem -VMMServer localhost | where {$_.Name -eq "Windows Server 2008 Standard 32-Bit"} New-VM -VMMServer localhost -Name "Demo-01" -Description "" -Owner "RBK\jer" -VMHost $VMHost -Path "D:\Hyper-V" -HardwareProfile $HardwareProfile -JobGroup 6928344f-7732-4e1b-b852-15cf0288cd2f -RunAsynchronously -OperatingSystem $OperatingSystem -RunAsSystem -StartAction NeverAutoTurnOnVM -StopAction SaveVM

Now you can save it as a ps1-file and tweak as wanted. This makes it really easy to get started automating tasks in SCVMM.

Btw, SC VMM 2008 is a really great product, making it possible to manage Virtual Server 2005, Hyper-V and VMWare ESX 🙂

December 18, 2008 Posted by | Scripting, Virtualization | Leave a comment