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

Help speeding up this Vmware Netapp script i wrote - Rdm are mapped to what netapp filer/lun

$
0
0

I wrote this script to figure out what netapp lun is used on each vm via ISCSI. Currently on about around 200 VM and 8 hosts it takes 40 Mins to run. This being my 3rd powershell script i am sure I could speed up its processing and was hoping someone could point me in the right direction.

 

 

This generates a csv file with the following header.

Hostname     DiskID     CapacityG     HD Path     ScsiCanonicalName LunID  Netapp Path

 

Also in function searchfilers i didn't know if anyone knew how to dynamically get this information, i have looked for hours/days and couldn't find a way besides hard coding it. This function is needed to know what netapp filer to connect to.

 

 

param([string]$VC)
Import-ModuleDataONTAP
#################Functions##############################################
function GetNetappPath([string]$VMHost,[string]$VMHDLunID,[string]$RuntimeName) {
$stor= get-view(Get-VMHostStorage-VMHost$VMHost)
$IscsiWWN= $stor.StorageDeviceInfo.HostBusAdapter | where{$_.GetType().Name -eq"HostInternetScsiHba"} | Select-First1 -expandpropertyIScsiName
Write-Host"Found ISCSI NAME: $IscsiWWN on Host $VMHost"
$c= SearchFilers $IscsiWWN$RuntimeName
Write-Host"Netapp path: $c"
return $c
}
function SearchFilers([string]$IscsiWWN,[string]$RuntimeName){
switch -wildcard($RuntimeName)
    {
       #Add all you vmware runtime names here with what filer
        "vmhba40:C0:T0*"{$NetappFiler= "x.x.x.x"}#ip address
       
        default {Write-host"Error! determining filer - $RuntimeName not found";read-host}
    }
Write-host"Connecting to $NetappFiler"
connect-nacontroller$NetappFiler| out-null
$Igroup= get-nalun| Get-Nalunmap| SelectName,Initiators | Where{$_.Initiators -like$IscsiWWN} | Select-First1 -expandpropertyName
$a= get-nalunbyigroup$Igroup$VMHDLunID| Select-ExpandPropertyPath
#Write-Host"SearchFilers function: $a"
$a= "$NetappFiler$a"#filerip\lunpath
return $a
}
function GetScsiTarget([string]$VMHost,[string]$SCSICanonicalName) {
$Lun= Get-SCSILun$SCSICanonicalName-VMHost$VMHost#(Get-VM $VMName).VMHost
$RuntimeName= $Lun| Select-ExpandPropertyRuntimeName
  return $RuntimeName
}
#################Functions##############################################
########################
$PathtoCSV= "C:\temp\VMlunIDNetappPath.csv"
########################
If ($VC){$strVC= $VC}
ELSE{$strVC= Read-Host"What is the Vcenter hostname?"}
If (!$strVC){Write-Host"Error: Vcenter not entered";exit}
Connect-VIServer-Server$strVC  #Enter your vCenter Server
#Create Header
"Hostname,DiskID,CapacityG,HD Path,ScsiCanonicalName,LunID,ESX Host,Netapp Path"> $PathtoCSV
Write-Host"Getting VM Information from Vcenter. This can take awhile based on how many VM you have"
$Disks= Get-VM| Get-HardDisk| Where{$_.DiskType -eq"RawPhysical"}
Write-Host"Completed getting VM Information from Vcenter"
Foreach($Diskin $Disks) {
$VMName= $_.Parent
write-host"VM Name: $VMName"
$VMHDname= $_.Name
write-host"Hard drive ID: $VMHDname"
$VMCapacityGB= $_.capacityGB
write-host"Lun Capacity(GB): $VMCapacityGB"
$VMHDPath= $_.filename
write-host"RAW VMDK Path: $VMHDPath"
$VMScsiCanonicalName= $_.ScsiCanonicalName
write-host"$ScsiCanonicalName: $VMScsiCanonicalName"
$VMHost= Get-VM$VMName| Select-ExpandPropertyHost
write-host"ESX Host: $VMHost"
$RuntimeName= GetScsiTarget $VMHost$Disk.SCSICanonicalName
write-host"RuntimeName: $RuntimeName"
$VMHDLunID= $RuntimeName.Substring($RuntimeName.LastIndexof(“L”)+1)
Write-Host"LunID: $VMHDLunID"
$NetappPath= GetNetappPath $VMHost$VMHDLunID$RuntimeName
Write-host"PathtoNetapp: $NetappPath"
$Combine= $VMName,$VMHDname,$VMCapacityGB,$VMHDPath,$VMScsiCanonicalName,$VMHDLunID,$VMHost,$NetappPath
Write-Host"Writing to $PathtoCSV"
$Combine-join",">> $PathtoCSV
}

 

 


Viewing all articles
Browse latest Browse all 252940

Trending Articles



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