Skip to content

PowerCLI Remove not connected LUN’s

21/01/2013

Quick post, will update later

#################################################
# Add Vmware Powercli snapin
If ((Get-PSSnapin "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "VMware.VimAutomation.Core"
}
#################################################
# Set Powercli Certification policy
Set-powercliconfiguration -InvalidCertificateAction Ignore -Confirm:$false | out-null
#################################################
#Connect to VIserver
$VIserver="MATTVISERVER"
Write-host "Connecting to $VIServer"
$server = Connect-VIServer -Server $VIServer -Protocol https
#################################################
# ESX Host
$vmhost="MATTESXHOST"
#################################################
# Connect to esxcli for $vmhost
$esxcli=get-esxcli -vmhost $vmhost
# List storage devices that are status not connected
$detached=$esxcli.storage.core.device.List() | where {$_.Status -eq "not connected" -and $_.Vendor -eq "NETAPP"}
Foreach ($lun in $detached) {
$device_id=$lun.Device
# Force device to be administratively offline
$esxcli.storage.core.device.set($device_id,"IsOffline",$null,"off")
# Force device to be administratively online
$esxcli.storage.core.device.set($device_id,"IsOffline",$null,"on")
# Rescan All HBA's
Get-VMHostStorage -VMHost $vmhost -RescanAllHBA
}

Advertisements

From → VMware

Leave a Comment

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

%d bloggers like this: