Reply to Message

View discussion in a popup

Replying to:
BenLiebowitz
Expert
Expert

Hey Luc,

I decided to find another way to run the partedUtil command...  I'm not getting the same results as I do if I run it via SSH though.  Is there a better way to get the Canonical Name of a LUN?

Thanks!

# connect to selected vCenter

connect-viserver $vcenter

# List Clusters

write-host ""

Write-host "Choose which Cluster where the LUN you want to remove presented:"

write-host "(it may take a few seconds to build the list)"

write-host ""

$ICLUSTER = get-cluster | Select Name | Sort-object Name

$i = 1

$ICLUSTER | %{Write-Host $i":" $_.Name; $i++}

$HCLUSTER = Read-host "Enter the number for the host to Patch."

$SCLUSTER = $ICLUSTER[$HCLUSTER -1].Name

write-host "You have selected $($SCLUSTER)."

start-sleep -s 3

# List hosts to select

write-host ""

Write-host "Choose which vSphere host that has the LUN presented."

write-host "(it may take a few seconds to build the list)"

write-host ""

$IHOST = get-cluster $SCLUSTER | Get-VMhost | Select Name | Sort-object Name

$i = 1

$IHOST | %{Write-Host $i":" $_.Name; $i++}

$DSHost = Read-host "Enter the number for the host to Patch."

$SHOST = $IHOST[$DSHost -1].Name

write-host "you have selected" $SHOST"."

# List all scsi devices

write-host ""

Write-host "Choose which LUN to remove.  *** VERIFY VIA THE vSPHERE CLIENT ***"

write-host "(it may take a minute to build the list)"

write-host ""

$ILUN = get-scsilun -vmhost $SHOST | Select LunDatastoreName, CanonicalName, RuntimeName, CapacityGB | Sort lundatastorename

$i = 1

$ILUN | %{Write-Host $i":" $_.lunDatastoreName, $_.RuntimeName, $_.CapacityGB; $i++}

$DSLUN = Read-host "Enter the number for the LUN to remove."

$SLUN = $ILUN[$DSLUN -1].LunDatastoreName

write-host "you have selected" $SLUN"."

# List the files on the LUN you selected

get-childitem (get-datastore $SLUN).datastorebrowserpath

# Check to see if the datastore is in use

Get-DatastoreUnmountStatus -datastore $SLUN

# Pipe datastore to get-scsilun to get canonicalname

$LUN = Get-Datastore $SLUN | get-scsilun | Select CanonicalName

# Start SSH

$ssh = Get-VMHostService -vmhost $SHOST | Where {$_.Key -eq "TSM-SSH"}

Start-VMHostService -HostService ($ssh) -Confirm:$false

# Remove the 99bnx2fc.sh file.

$User = "root"

$Pswd = "Password1!"

$plink = "c:\plink.exe"

$plinkoptions = " -v -batch -pw $Pswd"

$cmd1 = 'partedUtil getptbl /vmfs/devices/disks/$LUN'

$remoteCommand = '"' + $cmd1 + '"'

$command = $plink + " " + $plinkoptions + " " + $User + "@" + $SHOST + " " + $remoteCommand

$msg = Invoke-Expression -command $command

$msg

# Stop SSH

Stop-VMHostService -HostService ($ssh) -Confirm:$false

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.
Reply
0 Kudos