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

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!

https://gallery.technet.microsoft.com/Powershell-Script-to-b3ca124b

image

First we do set some variables for the script

# Variable
$vm= "MVPLOADTEST01"
$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
#Get-VMNetworkAdapterVlan

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

@clusterMVP

https://robertsmit.wordpress.com

Leave a Reply

Fill in your details below or click an icon to log in:

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 )

Google+ photo

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

Connecting to %s

  • Twitter

  • %d bloggers like this: