Månadsarkiv: november 2015

Automate the installation of Hyper-V VMintegration services with PowerShell

Tired of installing VM integration services manually in your Hyper-V environment? Here´s a script to help you with that!

Tip, this hotfix requires reinstallation of all your VMs integration services: Https://support.microsoft.com/en-us/kb/3063283

This script only works on x64 machines!


Begin Script

Powershell Script for updating of Hyper-V Integration Services
2015-11-23 Harri Förberg, Förbergs IT AB
Warning, this script could potentially reboot a lot of VM:s in rapid succession. Use wisely, and with caution.
Prequisites: Mount and copy the contents of C:\Windows\System32\vmguest.iso (found on your Hyper-V host), copy the content to a shared folder on the server that will used to execute the script
C:\Temp\IntegrationSvc is used in the script below
— You might need to have you GPO:s adjusted to allow file copy from the server where you execute this script. —

# Fill the latest Integration Services number here
$ICSVer = ”6.3.9600.17831” # This was the latest version 2015-11-23 (Delivered in a Hotfix – https://support.microsoft.com/en-us/kb/3063283)

#Specify your list of all Hyper-V Hosts
$HPVServer = ”HPV01” , ”HPV02” # <– Change to your servers

# Check all Running VM:s on all HPV hosts for ICS versions lower than our preset in line >> 13
$VMNames = Get-VM -ComputerName $HPVServer | ? {$_.IntegrationServicesVersion -lt $ICSVer -and $_.State -eq ”Running”} # This would be a good place to narrow your search parameters

# Check if any VM:s are in need of updating
($VMNames -eq $null) {Write-Host ”No VM:s detected with old versions” -ForegroundColor Red}
Write-Host ”Found VM:s with old Integration Services, starting upgrade process” -ForegroundColor Green

# Install Integration Services on VMs
foreach ($VirtualMachine in $VMNames)
$VMName = $VirtualMachine.VMName

# If copy fails here, check firewall rules on your client server.
write-host ”Copying installation files to $VMName
Copy-Item -Path C:\Scripts\IntegrationSvc -Destination ”\\$VMName\C$\temp\IntegrationSvc” -Recurse -Force
write-host ”Installing integration services…”
$scriptblock = {cmd.exe /C ”C:\Temp\IntegrationSvc\support\amd64\setup.exe /quiet /norestart”} # <– ADD or Remove /norestart if you want or dont want to reboot all VM:s after the installation completes!
Invoke-Command -scriptblock $scriptblock -computername $VMName
# Cleanup of copied installation files
write-host ”Cleanup…”
Remove-Item -Path ”\\$VMName\C$\temp\IntegrationSvc” -Recurse -Force
# Display Status
Write-Host $VMName updated” -ForegroundColor Green
Write-Host ”All done” -ForegroundColor DarkMagenta


End Script