Pages

6/30/2013

Gathering List of HP Blade Server WWN's

Powershell - Gather list of HP Blade Server WWN's

####################################################################################################
#
#  server-list.ps1
#
#  Gather inventory of profiles, bay assigned, and WWN's
#

$vcips = ("10.2.1.10","10.2.1.11")
$vcuser = "admin"
$outfile = ".\hpbl-wwns.csv"

$pw = Read-Host "Enter Password for $vcuser" -AsSecureString
$alldevicebays=@{}
$allprofiles=@()
$wwn1=@{}
$wwn2=@{}

clear-host

foreach ($vcip in $vcips) {

$profiles=@() #the profiles on this enclosure
$devicebays=@{}

$vcip

#convert $pw to plain text
	$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
		[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))

$go = "show profile" # Command Line

$result = (./plink.exe -batch -ssh -l $vcuser -pw $pass $vcip $go) | out-string
$pass ='' #erase plain txt pw
$list = ($result -split'[\n]')
if ($list.Length -lt 2) { break }

write-host "    Getting Profile List"

foreach ($item in $list) {
if ($item.Length -gt 0) {
    if (!$item.Contains("===============================================================")) {
        if (!$item.Contains("---------------------------------------------------------------")) {
            if (($item.Substring(0,1) -ne " ")) {
            $name = $item.Substring(0,12)
            $name = $name.Trim()
            $bay = $item.Substring(12,14)
            $bay = $bay.Trim()
                if ($name -ne "Name") { 
                    $profiles = $profiles + $name 
                    $allprofiles = $allprofiles + $name
                    $devicebays[$name] = $bay
                    $alldevicebays[$name] = $bay
                }
            }#end if
        } #end if
    }#end if
}#end if

}#end foreach

write-host "    Finding WWN's"

foreach ($profile in $profiles) {

write-host "        "$profile

    if ($devicebays[$profile] -ne "") {
#Port 1
$port = 1
write-host "            port "$port

		$go = "show fcoe-connection "+$profile+":"+$port
		$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
		[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))

		$result = (./plink.exe -ssh -l $vcuser -pw $pass $vcip $go) | out-string
		$pass=""
			$list = ($result -split'[\n]')
			foreach ($item in $list) {
				if ($item.Length -gt 0) {
					$items = ($item -split': ')
					$field = $items[0]
					$field = $field.Trim()          
					$data = $items[1]
					$data = $data.Trim()
					if ($field -eq "Port WWN") {
						$wwn1[$profile] = $data
					}#end if
				}#end if null
			}#end foreach item
#port 2
$port = 2
write-host "            port "$port

		$go = "show fcoe-connection "+$profile+":"+$port
		$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
		[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))

		$result = (./plink.exe -ssh -l $vcuser -pw $pass $vcip $go) | out-string
		$pass=""
			$list = ($result -split'[\n]')
			foreach ($item in $list) {
				if ($item.Length -gt 0) {
					$items = ($item -split': ')
					$field = $items[0]
					$field = $field.Trim()          
					$data = $items[1]
					$data = $data.Trim()
					if ($field -eq "Port WWN") {
						$wwn2[$profile] = $data
					}#end if
				}#end if null
			}#end foreach item
#end port 2

    }#end if UNASSIGNED
}#end foreach profile
}#end foreach enclosure

$profiles = $profiles | sort-object


#create report

write-host "generating output file: " $outfile

#delete output file if it exists
if ( test-path $outfile ) { remove-item $outfile }

get-date -format g | out-file $outfile -encoding ascii

"Profile, Bay, hbaA, hbaB" | out-file $outfile -encoding ascii -append
write-host "Profile, Bay, hbaA, hbaB"
foreach ($profile in $allprofiles) {
	$bay = ($alldevicebays[$profile])
	$wwnA = ($wwn1[$profile])
	$wwnB = ($wwn2[$profile])
	write-host $profile "," $bay "," $wwnA "," $wwnB
	write "$profile,$bay,$wwnA,$wwnB" | out-file $outfile -encoding ascii -append
}#end foreach

No comments: