Scripts

Welcome to the Nutanix NEXT community. To get started please read our short welcome post. Thanks!

cancel
Showing results for 
Search instead for 
Did you mean: 

Automate installation of VirtIO drivers for Windows Guests

Nutanix Employee

Automate installation of VirtIO drivers for Windows Guests

This script can be leveraged to bulk deploy any Nutanix MSI to multiple Windows hosts.  While this was developed to deploy the Nutanix MSI for VirtIO, this can also be leveraged for future Nutanix 

 

For example, this can be leveraged to deploy the Nutanix VirtIO MSI for installing VirtIO drivers in preparation for migrating windows hosts to Acropolis Hypervisor (AHV).  This can be run against a single Windows host or hundreds to make the migration to AHV much easier.

 

The code has been factored into a function which can be leveraged from any larger script or run ad-hoc.

 

 

############################################################
##
## Function: NTNX-Install-MSI
## Author: Steven Poitras
## Description: Automate bulk MSI installation
## Language: PowerShell
##
############################################################
function NTNX-Install-MSI {
<#
.NAME
	NTNX-Install-MSI
.SYNOPSIS
	Installs Nutanix package to Windows hosts
.DESCRIPTION
	Installs Nutanix package to Windows hosts
.NOTES
	Authors:  thedude@nutanix.com
	
	Logs: C:\Users\<USERNAME>\AppData\Local\Temp\NutanixCmdlets\logs
.LINK
	www.nutanix.com
.EXAMPLE
    NTNX-Install-MSI -installer "Nutanix-VirtIO-1.0.0.msi" `
		-cert "NutanixSoftware.cer" -localPath "C:\" `
		-computers $compArray -credential $(Get-Credential)
		
	NTNX-Install-MSI -installer "Nutanix-VirtIO-1.0.0.msi" `
		-cert "NutanixSoftware.cer" -localPath "C:\" `
		-computers "99.99.99.99"
#> 
	Param(
		[parameter(mandatory=$true)]$installer,
		
		[parameter(mandatory=$true)]$cert,
		
		[parameter(mandatory=$false)][AllowNull()]$localPath,
		
		[parameter(mandatory=$true)][Array]$computers,
		
		[parameter(mandatory=$false)][AllowNull()]$credential
	)

	begin{
		# Pre-req message
		Write-host "NOTE: the following pre-requisites MUST be performed / valid before script execution:"
		Write-Host "	+ Nutanix installer must be downloaded and installed locally"
		Write-Host "	+ Export Nutanix Certificate in Trusted Publishers / Certificates"
		Write-Host "	+ Both should be located in c:\"
				
		$input = Read-Host "Do you want to continue? [Y/N]:"
				
		if ($input -ne 'y') {
			break
		}
		
		if ($(Get-ExecutionPolicy) -ne 'Unrestricted') {
			Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force -Confirm:$false
		}
		
		# Import modules and add snappins
		Import-Module DnsClient
		Add-PSSnapin NutanixCmdletsPSSnapin -ErrorAction SilentlyContinue

		# Installer and cert filenames
		if ([string]::IsNullOrEmpty($localPath)) {
			# Assume location is c:\
			$localPath = 'c:\'
		}
		
		# Credential for remote PS connection
		if (!$credential) {
			$credential = Get-Credential
		}
		
		# Path for ADMIN share used in transfer
		$adminShare = "C:\Windows\"
		
		# Format paths
		$localInstaller = $(Join-Path $localPath $installer)
		$localCert = $(Join-Path $localPath $cert)
		$remoteInstaller = $(Join-Path $adminShare $installer)
		$remoteCert = $(Join-Path $adminShare $cert)
	
	}
	process {
		# For each computer copy file and install drivers
		$computers | %	{
			# Create a new PS Drive
			New-PSDrive -Name P -PSProvider FileSystem -Root \\$_\ADMIN$ `
				-Credential $credential
			
			# Copy virtio installer
			Copy-Item  $localInstaller P:\$installer
			
			# Copy Nutanix cert
			Copy-Item $localCert P:\$cert
			
			# Create PS Session
			$sessionObj = New-PSSession -ComputerName $_ -Credential $credential
			
			# Install certificate for signing
			Invoke-Command -session $sessionObj -ScriptBlock {
				certutil -addstore "TrustedPublisher" $args[0]
			} -Args $remoteCert
			
			# Install driver silently
			$installResponse = Invoke-Command -session $sessionObj -ScriptBlock {
				$status = Start-Process -FilePath "msiexec.exe"  -ArgumentList `
					$args[0] -Wait -PassThru
				
				return $status
			} -Args "/i $remoteInstaller /qn"
			
			if ($installResponse.ExitCode -eq 0) {
				Write-Host "Installation of Nutanix package succeeded!"
			} else {
				Write-Host "Installation of Nutanix package failed..."
			}
			
			# Cleanup PS drive
			Remove-PSDrive -Name P
		
			# Cleanup session
			Disconnect-PSSession -Session $sessionObj | Remove-PSSession
		}
	
	}
	end {
		
	}
}

 

http://nutanixbible.com
Tags (1)
8 REPLIES
Scout

Re: Automate installation of VirtIO drivers for Windows Guests

Might be a bit of a stupid question but where can we get hold of Nutanix-VirtIO-1.0.0.msi

Nutanix Employee

Re: Automate installation of VirtIO drivers for Windows Guests

Not a stupid question at all Smiley Happy  I believe this .MSI will be released with 4.5, will keep posted

http://nutanixbible.com
Wayfarer

Re: Automate installation of VirtIO drivers for Windows Guests

Great stuff, glad I'm not going mad!

Pathfinder

Re: Automate installation of VirtIO drivers for Windows Guests

Will Nutanix-VirtIO-1.0.0.msi install on windows 2003.

 

Thanks

 

 

Wayfarer

Re: Automate installation of VirtIO drivers for Windows Guests

Hi @TheDude

 

I don't suppose this .msi is available now that we are on version 4.5? Smiley Happy

Nutanix Employee

Re: Automate installation of VirtIO drivers for Windows Guests

Hi  @cvanable

 

Yup, it's on the Nutanix portal: https://portal.nutanix.com/#/page/static/supportTools

http://nutanixbible.com
Explorer

Re: Automate installation of VirtIO drivers for Windows Guests

So when we run this it moves the files to the C:\Windows folders but then fails everytime trying to install. We are not seeing the P: drive being added when we have a PS session open on the target VMWare VM either. 

We looked for logs but none were found on the machine we are running it from or the machine it is being run to. 

We are using the newest VirtIO drivers 1.1.1.

Any help would be appreciated.

Scout

Re: Automate installation of VirtIO drivers for Windows Guests

I have the same problem while trying to install version 1.1.1 using the .ps1 script.

Nothing happens in the Powershell/ CMD window when I run the script (tried different OSs and ran the Powershell unsighed execution policy before).

 

Nir