I have been hacking together this script to query all Vcenter VMs raw iscsi disks and return the following in a nice little csv file which my script sort of does. I know there is some optimization needed but I will get to that later. I am pretty new to powershell so i hope i am just overlooking something
Hostname | DiskID | CapacityG | HD Path | ScsiCanonicalName | LunID | Netapp Path) |
server name | Hard disk 3 | 40.00255108 | [VMFS_RDM] servername\servername.vmdk | naa.60 | 3 | /vol/volname/data.lun |
I have one issue i hope is simple
1. When returning the GetNetappPath function value i am getting System.Object you can see that i am calling that function at the bottom of this script $NetappPath = GetNetappPath $VMHost $VMHDLunID When i call function SearchFilers from the GetNetappPath function it seems to return the correct value and i put in Write-Host "GetNetappPath Function: $c" in the getnetapppath function and it seems to have the correct value. It looks like i returning the value from each function correctly, does anyone see something i did wrong to cause this?
I wrote in the SearchFilers function to search each filer then return a value. I have not put in that logic yet because I have the issue with problem 1
param([string]$VC)
#################Functions##############################################
function GetNetappPath([string]$VMHost,[string]$VMHDLunID) {
$stor = get-view (Get-VMHostStorage -VMHost $VMHost)
$IscsiWWN = $stor.StorageDeviceInfo.HostBusAdapter | where {$_.GetType().Name -eq "HostInternetScsiHba"} | Select -First 1 -expandproperty IScsiName
Write-Host "Found ISCSI NAME: $IscsiWWN on Host $VMHost"
$c = SearchFilers $IscsiWWN
Write-Host "GetNetappPath Function: $c" <-------- this value contains the name of the filer which shouldn't be returning along with the path
return $c <-----------------------This return is where i am having the issue
}
function SearchFilers([string]$IscsiWWN){
connect-nacontroller servername
$Igroup = get-nalun | Get-Nalunmap | Select Name,Initiators | Where {$_.Initiators -like $IscsiWWN} | Select -First 1 -expandproperty Name
$a = get-nalunbyigroup $Igroup $VMHDLunID | Select -ExpandProperty Path
Write-Host "SearchFilers function: $a"
return $a
}
function GetLunInfo([string]$VMHost,[string]$SCSICanonicalName) {
$Lun = Get-SCSILun $SCSICanonicalName -VMHost $VMHost #(Get-VM $VMName).VMHost
$VMHDLunID = $Lun.RuntimeName.Substring($Lun.RuntimeName.LastIndexof(“L”)+1)
return $VMHDLunID
}
#################Functions##############################################
########################
Import-Module DataONTAP
########################
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
$PathtoCSV = "C:\temp\VMlunID.csv"
"Hostname,DiskID,CapacityG,HD Path,ScsiCanonicalName,LunID,Netapp Path)" > $PathtoCSV
Write-Host "This will take a bit to run"
$Disks = Get-VM | Get-HardDisk | Where {$_.DiskType -eq "RawPhysical"}
Write-Host "Finished getting disk info"
Write-Host ""
Write-Host "Figuring out lun information"
Foreach ($Disk in $Disks) {
$VMName = $Disk.Parent
$VMHDname = $Disk.Name
$VMCapacityGB = $Disk.capacityGB
$VMHDPath = $Disk.filename
$VMScsiCanonicalName = $Disk.ScsiCanonicalName
$VMHost = Get-VM $VMName | Select -ExpandProperty Host
#Write-Host $VMName,$VMHDname,$VMCapacityGB,$VMHDPath,$VMScsiCanonicalName
#LunID
Write-Host "Figuring out lun ID"
$VMHDLunID = GetLunInfo $VMHost $Disk.SCSICanonicalName
Write-Host "Figuring out Netapp Igroup Information and Path"
$NetappPath = GetNetappPath $VMHost $VMHDLunID
$Combine = $VMName,$VMHDname,$VMCapacityGB,$VMHDPath,$VMScsiCanonicalName,$VMHDLunID,$NetappPath
Write-Host "Writing $Combine"
$Combine -join "," >> $PathtoCSV
}