PowerShell Test

By Andy at April 07, 2010 01:10
Filed Under: PowerShell
Technorati Tags: ,

 

This is a test of Syntax Highlighter for PowerShell…

## Get-ICVersions.ps1

## Check to see if the VMM Snap-In is loaded, if not load it.
if (!(Get-PSSnapin Microsoft.SystemCenter.VirtualMachineManager -ea SilentlyContinue)) 
	{
	Write-Host "Loading VMM Snap-In..."
	Add-PSSnapin -Name Microsoft.SystemCenter.VirtualMachineManager -ea SilentlyContinue
	if (!$?) 
		{
			Write-Host "VMM Snap-In not Found! This Script Requires the SCVMM Snap-In be installed!" -ForegroundColor Red
			break
		}
	}

## Get a connection to the VMM Server. Change localhost to your VMM server.
Get-VMMServer localhost | Out-Null

## Get a list of all the VM Names
$VMs = Get-VM

foreach ($VM in $VMs)
	{
		## Create an object to use for our results
		$Result = New-Object System.Object
		$VMName = $VM.ComputerName
		
		## Build the path to the driver we will use to get the IC Version.
		$File = "\\$VMName\c$\windows\system32\drivers\vmbus.sys"
		
		## Handle errors if the VM is inaccessible, turned off, etc.
		trap [System.Management.Automation.MethodInvocationException] {continue}
		## Get the file version from the driver file.
		$Driver = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($File)
		if (!$?) 
			{
				## Set the driver version to something if we can't get to it.
				$DriverVersion = "Inaccessible"
			}
			else
				{
					$DriverVersion = $Driver.ProductVersion
				}
		
		## Build the results and return them as an object.
		$Result | Add-Member -MemberType NoteProperty -Name Server -Value $VMName
		$Result | Add-Member -MemberType NoteProperty -Name ICVersion -Value $DriverVersion
		$Result
	}

Tag cloud

Month List