Using PowerCLI to find all the VM’s with ISO’s attached


#Create an instance of the Excel.Application
$xl = New-Object -comobject excel.application
$xl.Visible = $true
$xl.DisplayAlerts = $False
$wb = $xl.Workbooks.Add()
$ws = $wb.Worksheets.Item(1)
$ws1 = $wb.worksheets | where {$_.name -eq "Sheet1"} #<------- Selects sheet 1

$ws1.Cells.Item(1,1) = “VM”
$ws1.Cells.Item(1,2) = “CD Drive ISOPath”
$row = 2

$vms = get-vm | select Name | sort
foreach ($i in $vms) {
$Item = [string]$i
$g = $Item.Split(“=”)
$Name = $g[1].Trimend(“}”)
$CDConnected = Get-CDDrive $Name | where { ($_.ConnectionState.Connected -eq “true”) -and ($_.ISOPath -like “*.ISO*”)}
If ($CDConnected -ne $null) {
$ws1.Cells.Item($row,1) = $Name
$ws1.Cells.Item($row,2) = $CDConnected.IsoPath
$row++
[void]$ws1.cells.entireColumn.Autofit()
}
}

[\sourcecode]

Advertisements

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