PowerShell Creating and Deploying Virtual Machines in VMM for Azure Pack #wapack #cloud #scvmm #Microsoft

Now that More and more customers are using SCVMM and with Clustering. I decided that I should post some helpful easy PowerShell scripts.

Ok I’m no Posh MVP the scripts are working and will get you started with things.

The First script I post is a Create a Virtual Machine with Powershell Based on a VHDX that is also used for VMM.

The Script can be found here  “Powershell Script to Create Hyper VM and copy syspreped VHDX to CSV “ it is still a GEN 1 VM!



First we do set some variables for the script

# Variable
$SMBShare= "SMBVM01"
$CPU= 2
$mem= 4GB
$HVcluster= "MVPTENANT001"
$VlanID= 1234
$HVswitch="Tenant Switch"

Next step is create a new VM and place this on the SMB share

# Create New VM
New-VM -Path \\MVPSofs001\$SMBShare\ -Name $vm -Generation 1 -newVHDPath "\\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$VM.VHDX" -NewVHDSizeBytes 5GB -SwitchName $HVswitch -Memory 4GB

As the Disk is just a place holder and will be replaced by my template.

#VM adjustments Dynamic or Fixed
# Set-VM -Name $vm -DynamicMemory -MemoryMaximumBytes 4GB -MemoryMinimumBytes 4GB -MemoryStartupBytes 4GB -ProcessorCount 2
Set-VM -Name $vm -StaticMemory -MemoryStartupBytes "$mem" -ProcessorCount "$CPU"

Set a Vlan if needed else use the #

# Set VLAN
Set-VMNetworkAdapterVlan –VMName $vm -Access –VlanId $vlanid

Now that the VM is in place and connected I’ll replace the placeholder disk and use my own syspreped disk. from the SCVMM library

# Copy Template Disk
Copy-Item -Path "\\MVPSofs001\VMMLibrary\Templates\2012R2RU2.*" -Container -Destination "\\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$vm _Disk_C.vhdx" -Recurse

# Remove Old Disk
Remove-VMHardDiskDrive -VMName $vm -ControllerType IDE -ControllerLocation 0 -ControllerNumber 0

# Add syspreped disk
Add-VMHardDiskDrive -VMName $vm -path "\\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$vm _Disk_C.vhdx" -ControllerType IDE -ControllerLocation 0 -ControllerNumber 0

Or if you need More harddisks use this

# Add-VMHardDiskDrive -VMName $vm -path "\\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$vm _Disk_D.vhdx" -ControllerType SCSI

# Delete Old Disk
Remove-Item -Path \\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$vm.vhdx

#Add VM TO Cluster
Get-VM $vm | Add-VMToCluster -Cluster $HVcluster
Start-VM $vm

Easy Step by Step with a HA VM

Happy clustering

Robert Smit



Author: Robert Smit [MVP]

Robert Smit is Senior Technical Evangelist and is a current Microsoft MVP in Clustering as of 2009. Robert has over 20 years experience in IT with experience in the educational, health-care and finance industries. Robert’s past IT experience in the trenches of IT gives him the knowledge and insight that allows him to communicate effectively with IT professionals who are trying to address real concerns around business continuity, disaster recovery and regulatory compliance issues. Robert holds the following certifications: MCT - Microsoft Certified Trainer, MCTS - Windows Server Virtualization, MCSE, MCSA and MCPS. He is an active participant in the Microsoft newsgroup community and is currently focused on Hyper-V, Failover Clustering, SQL Server, Azure and all things related to Cloud Computing and Infrastructure Optimalization. Follow Robert on Twitter @ClusterMVP Or follow his blog https://robertsmit.wordpress.com Linkedin Profile Http://nl.linkedin.com/in/robertsmit Robert is also capable of transferring his knowledge to others which is a rare feature in the field of IT. He makes a point of not only solving issues but also of giving on the job training of his colleagues. A customer says " Robert has been a big influence on our technical staff and I have to come to know him as a brilliant specialist concerning Microsoft Products. He was Capable with his in-depth knowledge of Microsoft products to troubleshoot problems and develop our infrastructure to a higher level. I would certainly hire him again in the future. " Details of the Recommendation: "I have been coordinating with Robert implementing a very complex system. Although he was primarily a Microsoft infrastructure specialist; he was able to understand and debug .Net based complext Windows applications and websites. His input to improve performance of applications proved very helpful for the success of our project

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: