PowerShell Script for Automated Install of Hyper-V Integration Services in a VM running on Windows Server 2012 with Hyper-V V 3.0 Role using PowerShell Remoting

PowerShell Script for Automated Install of Hyper-V Integration Services in a VM running on Windows Server 2012 with Hyper-V V 3.0 Role using PowerShell Remoting
Hi Guys i stumbled upon Something Super Exciting i was able to do With Hyper-V V3 Installed on Windows Server 2012 server, I was fully able to automate the installation of integration services in a Virtual Machine using the New Hyper-V Powershell Cmdlets bundled with Windows Server 2012.I created an advanced function to automate installation of Integration Services on a VM.

Here are some script sceenshots which illustrate the entire script run process from start to finish 🙂 wohooo 🙂 its a cool achievement

Now if i Run the script again that is after the integration services are upgraded it gives me this output :),

Neat!!, it shows that we are running on latest version of Integration Services as Hyper-V Version 3.0

First i went through the Hyper-V Module and i was amazed to see that now we are being shipped with 164 🙂 set of New Cmdlets, plain Awesome!!, and the new cmdlets were much feature packed as compared to the CodePlex edition of Hyper-V Modules.

In The Script i’m using a new cmdlet being shipped with Hyper-V v3 which can be used to
associate an .iso image with a Virtual Machine.

After This i extracted the DVD Drive letter for a VM using the new cmdlet Get-VMDvdDrive.


I was able to get a little help from Adam in his blog for Hyper-V http://csharpening.net/?p=1052 which shows on how to extract the DVD drive letter using split-path and its parameter -Leaf.

Then i went on and extracted the Hyper-V Host Integration Service Version and The Virtual Machine Integration Service version using the below commands.


Then i made a compare between them in an if-else loop, The If condition evaluated out as below and streamed the output to the pipeline with the Integration Service Version on Both the VM and Hyper-V Host.

Once the script see’s that Integration Services Version is the same on both the VM and The Hyper-V Host, i used the Set-VMDVDdrive cmdlet to eject the vmguest.iso attached to the VM


In the Else Loop i used Invoke-Wmi Method to  Install the integration services on the Virtual Machine with out a restart.

Once the wmi command got completed i put a while loop in the script to check if the setup service got started and waited for it to finish, which implicates wait for the integration service to get installed.

Once the installation was done i invoked a Restart-Computer with a wait for WinRM service to come up :), now thats a super neat feature in New PowerShell v3 🙂

Once the Server Got Restarted i was able to see this pretty cool output on my powershell prompt that the integration services version did get upgraded to latest as per Hyper-V 3 🙂

write-verbose “$vm Is Online Now” -Verbose

Here’s the Entire Script For Your Reference 🙂


Please follow and like us:

Share this post

16 thoughts on “PowerShell Script for Automated Install of Hyper-V Integration Services in a VM running on Windows Server 2012 with Hyper-V V 3.0 Role using PowerShell Remoting

  1. Verry good script, I use a cluster and I had to change:

    Set-VMDvdDrive -VMName $vm -Path "C:WindowsSystem32vmguest.iso"


    Set-VMDvdDrive -VMName $vm -Path "C:WindowsSystem32vmguest.iso" -AllowUnverifiedPaths

    But everything works great now.

  2. I'm a powershell noob, but I tested your script in my lab with Server 2012 R2 and it worked great! Upgraded all my VM and I learned alot. Thanks for sharing!

  3. when I run the command nothing happens? I am running from windows server 2012.. I copied the script to a folder and running the command from there..
    Install-VMIntegrationService -VMName "ev.VMWIN2K8R2-1.H" -VMComputerName "VMWIN2K8R2-1" -username

    what is ev.VMWIN2K8R2-1.H means?

  4. Thanks for the script!
    How would you use this script if you want to use it on three hyper-v hosts, each of them running 40-50 vm´s?


  5. hi im new to power shell is there any material to automate the virtual machine creation in hyper-v using powershell along with adding the network and also the iso files also

  6. # This script creates a new Hyper-V machine with hard drive, memory & network resources configured.

    # Variables
    $SRV1 = Read-Host "Enter the Virtual Machine name (Press [Enter] to choose Server01): "
    if ($SRV1 -eq ""){$SRV1="Server01"} ; if ($SRV1 -eq $NULL){$SRV1="Server01"}

    $SRAM = Read-Host "Enter the size of the Virtual Machine Memory (Press [Enter] to choose 512MB): "
    if ($SRAM -eq ""){$SRAM=512MB} ; if ($SRAM -eq $NULL){$SRAM=512MB}

    $SRV1VHD = Read-Host "Enter the size of the Virtual Machine Hard Drive (Press [Enter] to choose 40GB): "
    if ($SRV1VHD -eq ""){$SRV1VHD=40GB} ; if ($SRV1VHD -eq $NULL){$SRV1VHD=40GB}

    $VMLOC = Read-Host "Enter the location of the Virtual Machine file (Press [Enter] to choose C:HyperV): "
    if ($VMLOC -eq ""){$VMLOC="C:HyperV"} ; if ($VMLOC -eq $NULL){$VMLOC="C:HyperV"}

    $Network1 = Read-Host "Enter the name of the Virtual Machine Network (Press [Enter] to choose Network1): "
    if ($Network1 -eq ""){$Network1="Network1"} ; if ($Network1 -eq $NULL){$Network1="Network1"}

    $ISOPath=Read-Host "Enter the path of the Image file to add to the Virtual Machine: "

    #write the output of the user input
    write-output " "
    write-output " "
    write-output " "
    write-output " "
    write-output " "
    write-output "the user input values are as below:"
    write-output "The Virtual Machine Name is :" $SRV1
    write-output "The size of virtual machine is :" $SRAM
    write-output "The size of the Virtual Machine Hard Drive is :" $SRV1VHD
    write-output "The location of the Virtual Machine file is:" $VMLOC
    write-output "The Virtual Machine Network is:" $Network1
    write-output "The Virtual Machine ISOPath is:" $ISOPath

    # Configure Hyper-V Virtual Network
    remove-vmswitch $Network1 -force -erroractionsilentlycontinue
    new-vmprivateswitch $Network1

    # Create Virtual Machines
    MD $VMLoc -erroractionsilentlycontinue
    new-vm $SRV1 -path $VMLoc
    new-vhd -vhdpaths $VMLoc$SRV1 -size $SRV1VHD
    add-vmdisk -vm $SRV1 -controllerid 0 -lun 0 -path $VMLoc$SRV1
    get-vm $SRV1 | add-vmdrive -controllerid 1 -lun 0 -dvd
    get-vm $SRV1 | set-vmmemory -memory $SRAM
    get-vm $SRV1 | add-vmnic -virtualswitch $Network1
    Add-VMDvdDrive -VMName $SRV1 –Path $ISOPath

    Will the above code work


Post Comment

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