Skip to Content

VMware get-lunpathsetting.ps1

Recently had a need to validate the configured LUN path settings in some of our VMware environments. The prospect of checking them through the VIClient GUI was less then appealing as was checking via command line on each VMhost. So I used VMware's new PowerCLI PowerShell plugin to automate the information gathering. After I did this, my co-worker found a script to set preferences by odd/even Set HBA Preference

We have multiple environments so I tried to make the settings as generic as possible. I added date/time and VIServer to the file name so that it wouldn't get over written if you were running it before and after a configuration change or against different environments.

Using VMware's PowerCLI plugin for PowerShell I came up with this script.

# ===========================================================================
# NAME: get-lunpathsetting.ps1
# AUTHOR: Steven Peck
# DATE  : 9/15/2009
#
# COMMENT: Get the settings for SCSI lun path and which is active
#
# ===========================================================================

# Set variables
# The VIServer is separated from domain so I can use it in the file name.
# Date and time are used to help not overwrite existing files.
$viserver = "sacpreapp100"
$domain = ".company.com"
$filepath = "C:\support\scripts\vmware"
$date = Get-Date -uformat %Y%m%d
$time = Get-Date -uformat %H%M

connect-viserver $viserver$domain

$report = @()

$Vmhosts = Get-VMhost

foreach ( $computer in $Vmhosts ) {
Write-Host $computer
$path = $computer | Get-ScsiLun | Get-scsilunpath | select Lunpath, State, Preferred, SanID
  foreach ( $item in $path ) {
    $object = New-Object -typename System.Object
    $object | Add-Member -MemberType noteProperty -name VMhost -value $computer
    $object | Add-Member -MemberType noteProperty -name Lunpath -value $item.Lunpath
    $object | Add-Member -MemberType noteProperty -name State -value $item.State
    $object | Add-Member -MemberType noteProperty -name Preferred -value $item.Preferred
    $object | Add-Member -MemberType noteProperty -name SanID -value $item.SanID
    $report += $object
  }
}
#
# $report | select VMhost, Lunpath, State, Preferred, SanID
$report | sort VMhost | Export-Csv $filepath\$date$time$viserver"LunPathValue.csv" -NoType

Comments

How to call this object .

How to call this object . because this is not execute .
$object | Add-Member -MemberType noteProperty -name VMhost -value $computer
$object | Add-Member -MemberType noteProperty -name Lunpath -value $item.Lunpath
mcitp | mcts