Category: System Center

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…



How to Backup a Sharepoint 2010 Site Collection with Powershell

Powershell HeaderOkay for a real backup solution you should use a backup software like Microsoft System Center Data Protection Manager or Symantec Backup Exec. But maybe you have customer which needs a backup of his Sharepoint Site Collection. You also could use the Backup Tool in the Sharepoint Central Administration, but if you need to automate that, you will need Powershell.

Backup a Site Collection:

Backup-SPSite -Identity "http://sharepoint.company.com" -Path "C:\Temp\backup1.bak" -Force

Restore a Site Collection:

Restore-SPSite "http://sharepoint.company.com" -Path C:\backup1.bak -HostHeaderWebApplication "http://WebAppname" -Force -Confirm:$False


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



Howto: Update SCVMM 2008 to SCVMM 2008 R2

Update from Microsoft System Center Virtual Machine Manager 2008 to Micorsoft System Center Virtual Machine Manager 2008 R2 is pretty simple. Yesterday I updated the SCVMM on our environment.

  1. Copy the SCVMM 2008 R2 on the Server
  2. Start the Setup.exe
  3. Install VMM Server, the installer check that this is an update of an existing installation
  4. System Center Virtual Machine Manager 2008 R2 Update After updating the VMM Server you have to install the new VMM Administrator Console and the new Self-Service Portal if needed.
  5. The installer of the VMM Administrator Console and the VMM Self-Service Portal will first uninstall the old version and then install the new version.
  6. After installing the SCVMM 2008 R2 you have to check for Windows Updates
  7. After a rebooting the SCVMM Server you have to push the new Agent Update to the Virtual Host Servers
  8. Now you are done

Whats new in System Center Virtual Machine Manager 2008 R2:

  • Support for Live Migration
  • Hot addition/removal of Storage
  • New optimized networking technologies
  • Cluster Shared Volumes
  • SAN migration
  • Expanded Support for iSCSI SANs
  • Storage Migration
  • Rapid Provisioning
  • Support for third party CFS
  • Support for Veritas Volume Manager
  • Added Maintenance Mode
  • Support of disjoint domains
  • Use of defined port groups with VMware Virtual Center
  • Queuing of Live migrations
  • Host Compatibility checks