Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 244595

Re: Detach a lun using datastore name?

$
0
0

Thanks luc you got me pointed in the right direction.  I was trying to determine how to get naa id from datstore name and after looking a the script you sent i got it figured out with this

$hostviewDSDiskName

=$ds.ExtensionData.Info.vmfs.extent[0].Diskname

 

So i took your  function to fit my existing script i have that reads in datastores and hosts spreadsheet!

 

hosts file just column with header "host" then hostnames

and datastore list with title datastore

 

 

. .\detach-function.ps1

 

$vcenter = Read-Host "Enter Vcenter Name"
$list = read-host "Enter host list filename"

Connect-VIServer $vcenter

$hostslist = import-csv $list
$datastorelist = import-csv datastores.csv


foreach ($vmhost in $hostslist){
   $esx = Get-VMHost $vmhost.host
  foreach ($ds in $datastorelist){
     $datastore = Get-Datastore $ds.datastore
  $naaid = $datastore.ExtensionData.Info.vmfs.extent[0].Diskname
  Detach-disk -VMhost $esx -CanonicalName $naaid
}
}

Disconnect-VIServer $vcenter -Confirm:$false


Viewing all articles
Browse latest Browse all 244595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>