Using Powershell v3 Workflow with HyperV deployment
Now that the Windows 2012 RC has arrived with the Powershell v3 I wanted to explore the functionality a bit more, I have seen some posts about how to use the Workflows but none when deploying VM´s in Hyper-V.
I have loaned some code from Mikael Nyström (Deployment Bunny) but had to rewrite a little to make it work with the workflow -parallel.
Also when I downloaded Mikael´s scripts they where automatically blocked ( I had set my demo system to -Unrestricted) but as you see in the screenshot they are still blocked. but luckily I can use the Unblock-File cmdlet in the Powershell v3, when using the v2 there was a utility tool streams.exe from SysInternals that could help.

and here is it in the properties dialog

But if I have like 5-10 or 100 files I would like to use Powershell (Anyone out there unblocking like 100 scriptfiles by clicking in a dialog?)

To create the “Master” vhdx I used the Convert-WindowsImage.ps1 script, I am creating the master to be deployed with win 2012 RC datacenter core version (Updated:I got a tip in the comments to look at the Convert-WindowsImage instead of the Wim2VHD.ps1)

Now to my workflow, I am testing to create 5 VM´s at the same time with differential disks connected to the master. the workflows also set all VM´s to dynamic memory and starts them.

# Inparallel.ps1 # # Niklas Akerlund # 2012-06-03 workflow create-VMs { $VMRefDisk = "C:\VMs\master.vhdx" $VMNetwork = "Intern" $VMBaseLocation = "C:\VMs" $VMMemory = 384MB foreach -parallel ($item in 1..5) { $VMName = "TestVM$item" $VMLocation = New-Item -Path "$VMBaseLocation\$VMName" -ItemType Directory -Force $VMDiskLocation = New-Item -Path "$VMLocation\Virtual Hard Disks" -ItemType Directory -Force $VMDisk01 = New-VHD –Path $VMDiskLocation\$VMName-OSDisk.vhdx -Differencing –ParentPath $VMRefDisk New-VM –Name $VMname –MemoryStartupBytes $VMMemory –VHDPath $VMDisk01.path -SwitchName $VMNetwork -Path $VMBaseLocation Set-VM -VMName $VMName -DynamicMemory Start-VM -VMName $VMName } Get-VM TestVM* }
It is quite simple but still powerfull, If I for example had like more hosts i can deploy many VM´s at the same time and the thing that would stop me is the hardware and the storage 😛
Comments
Thought it would be worth a mention here:
http://gallery.technet.microsoft.com/scriptcenter/Convert-WindowsImageps1-0fe23a8f
An update to Win2VHD, called Convert-WindowsImage.
@BRW
I think i referred to it in in a tweet, I did not think of it when creating the post, I will update with the Convert-WindowsImage.ps1 🙂