Powershell for System Center Virtual Machine Manager and Hyper-V

Microsoft System Center Virtual Machine Manager 2008 R2

This little HowTo shows you how can you get tasks on System Center Virtual Machine Manager done, by using Windows Powershell.

Load Powershell Snapin for Virtual Machine Manager:

Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

Create Virtual Machine:

# Config
# ------------------------------------
# Job Config
$JobGroup = "0000001" # This is used to group command by a job
$SCMVVMServer = "SCVVMServer01" # Name of the SCVMM Server (could also be localhost)

# Network Config
$VirtualNetwork = "External" # Name of the Network you want the VM to connect
$VLanEnable = $true # eable VLANs
$VLANID = "1023" # VLAN ID

# VMM Config
$Domain = "Contoso"
$Owner = "Ownerusername" # Owner User
$Description = "This is a Server" # Choose a Description
$VMName = "server05" # Name of the VM
$VMHost = "hyperv02" # Name of the existing VM Host
$VMPath = "C:\ProgramData\Microsoft\Windows\Hyper-V"

# Virtual Machine Config
$VMOperatingSystem = "64-bit edition of Windows Server 2008 R2 Standard"
$CPU = "1.20 GHz Athlon MP" # CPU
$VMDiskSize = "40960" # Disk Size in MB
$CPUCount = "1"
$MemoryMB = "1024" # Memory Size in MB
$ExpectedCPUUtilization = "20"
$DiskIO = "0"
$CPUMax = "100"
$CPUReserve = "0"
$NetworkUtilization = "0"
$RelativeWeight = "100"
$HighlyAvailable = $false
$NumLock = $false
$BootOrder = "CD", "IdeHardDrive", "PxeBoot", "Floppy"
$LimitCPUFunctionality = $false
$LimitCPUForMigration = $false

# Setup Process
# ------------------------------------
Set-VirtualFloppyDrive -RunAsynchronously -VMMServer $SCVMMServer -NoMedia -JobGroup $JobGroup
Set-VirtualCOMPort -NoAttach -VMMServer $SCVMMServer -GuestPort 1 -JobGroup $JobGroup
Set-VirtualCOMPort -NoAttach -VMMServer $SCVMMServer -GuestPort 2 -JobGroup $JobGroup
New-VirtualNetworkAdapter -VMMServer $SCVMMServer -JobGroup $JobGroup -PhysicalAddressType Dynamic -VirtualNetwork $VirtualNetwork -VLanEnabled $VLanEnable -VLANID $VLANID -MACAddressesSpoofingEnabled $false
$CPUType = Get-CPUType -VMMServer $SCVMMServer | where {$_.Name -eq $CPU}
New-HardwareProfile -VMMServer $SCVMMServer -Owner ($Domain + "\" + $Owner) -CPUType $CPUType -Name ("Profile" + $JobGroup) -CPUCount $CPUCount -MemoryMB $MemoryMB -ExpectedCPUUtilization $ExpectedCPUUtilization -DiskIO $DiskIO -CPUMax $CPUMax -CPUReserve $CPUReserve -NetworkUtilization $NetworkUtilization -RelativeWeight $RelativeWeight -HighlyAvailable $HighlyAvailable -NumLock $XMLTask.Feature.NumLock -BootOrder $BootOrder -LimitCPUFunctionality $LimitCPUFunctionality -LimitCPUForMigration $LimitCPUForMigration -JobGroup $JobGroup
New-VirtualDiskDrive -VMMServer $SCVMMServer -IDE -Bus 0 -LUN 0 -JobGroup $JobGroup -Size $VMDiskSize -Dynamic -Filename ($VMName + "_disk_1")
$VMHost = Get-VMHost -VMMServer $SCVMMServer | where {$_.Name -eq $VMHost}
$HardwareProfile = Get-HardwareProfile -VMMServer $SCVMMServer | where {$_.Name -eq ("Profile" + $JobGroup)}
$OperatingSystem = Get-OperatingSystem -VMMServer $SCVMMServer | where {$_.Name -eq $VMOperatingSystem}

# Create VM
# ------------------------------------
New-VM -VMMServer $SCVMMServer -Name $VMName -Description $Description -Owner ($Domain + "\" + $Owner) -VMHost $VMHost -Path $VMPath -HardwareProfile $HardwareProfile -JobGroup $JobGroup -RunAsynchronously -OperatingSystem $OperatingSystem -RunAsSystem -StartAction NeverAutoTurnOnVM -StopAction SaveVM

Delete (Remove) Virtual Machine:

# Config
# ------------------------------------
$VMName = "server05" # Name of the VM

# Setup Process
# ------------------------------------
$SelectedVM = Get-VM -Name $VMName

# Remove/Delete VM
# ------------------------------------
Remove-VM -VM $SelectedVM

Suspend Virtual Machine:

# Config
# ------------------------------------
$VMName = "server05" # Name of the VM

# Setup Process
# ------------------------------------
$SelectedVM = Get-VM -Name $VMName

# Suspend VM
# ------------------------------------
Suspend-VM -VM $SelectedVM

Resume Virtual Machine:

# Config
# ------------------------------------
$VMName = "server05" # Name of the VM

# Setup Process
# ------------------------------------
$SelectedVM = Get-VM -Name $VMName

# Resume VM
# ------------------------------------
Resume-VM -VM $SelectedVM

Stop Virtual Machine / Turn off Virtual Machine:

# Config
# ------------------------------------
$VMName = "server05" # Name of the VM

# Setup Process
# ------------------------------------
$SelectedVM = Get-VM -Name $VMName

# Stop / Turn off VM
# ------------------------------------
Stop-VM -VM $SelectedVM

Start Virtual Machine:

# Config
# ------------------------------------
$VMName = "server05" # Name of the VM

# Setup Process
# ------------------------------------
$SelectedVM = Get-VM -Name $VMName

# Start VM
# ------------------------------------
Start-VM -VM $SelectedVM

This is a reference how you can do some thing with Powershell in the Virtual Machine Manager. You can do a lot more, like error handling, creating virtual machines from a xml config file etc…

SCVMM 2008 R2 adding VLANs

Microsoft System Center Virtual Machine Manager 2008 R2

In Microsoft System Center Virtual Machine Manager 2008, SCVMM added the VLAN automatically to the VM Hosts VLAN Trunk , if you added the VLAN to a Virtual Machine.

Hyper-V SCVMM Virtual Machine PropertiesIn Microsoft System Center Virtual Machine Manager 2008 R2 (SCVMM 2008 R2), this does not happen automatically. After or before you added the VLAN to the Virtual Machine you have to add the specific VLAN to the Host network adapter.

In the properties of the Virtual Machine Host under networking you have to edit the VLN Trunk.

Hyper-V SCVMM VLAN Trunk propertiesNow you can add VLAN IDs to the VLAN Trunk:

Hyper-V SCVMM VLAN Trunk

Tuning a Windows 7 VM

I run several Windows Virtual Machines (VMs) on my Mac with VMware Fusion. Even VMware Fusion has a great performance for Virtual Machines I am really happy about every performance increase I can get. I made a list with some tuning tips.

  • First use Windows Classic Theme
  • Deactivate System Protection (You also win some Diskspace)
  • Under System Properties –> Advanced –> Performance –> Choose Adjust for best Performance
  • Deactivate Autostart objects with MSCONFIG

There are a lot of more tips out there but I thinks these are pretty important.

Time sync problems with Hyper-V Guests

If you have time sync problems with Hyper-V Guest Systems there is a simple solution for this.

Problems:

  • Time between Server and Active Directory Domain Controller is not correct
  • Can’t login because of this
  • Can’t add AD Users to local groups

Solution:

To solve this problem you have to disable Time Synchronization in the Hyper-V Integration Services for each guest. Then restart the Windows Time serviceon the guest. The guests will then correctly synchronize with a domain controller.

Update: VMware Fusion 3.0.1 Graphic Awesomeness

I just updated my VMware Fusion on my MacBook Pro and my iMac at work. I did some snapshots of the Windows Experience score in my Windows 7 VM.

With this Update the VMware Fusion Team did a really good job on the graphics drivers:

VMware Fusion 3.0:
Windows 7 @ VMware Fusion 3.0

VMware Fusion 3.0.1:
Windows 7 @ VMware Fusion 3.0.1

They also fixed over 50 bugs and added new features, checkout the VMware Fusion Blog.