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

output variables to excel spreadsheet.

$
0
0

Hi

I wrote this script, it works perfectly but I cant output this script to a excel document. Anyone knows how to do that?

 

 

$list = get-content -Path D:\vCenterList.txt #List of your vcenter to retrieve storage wwn targets from
$username =' '  #vCenter login name
$Password =' '  #vCenter password
$report = @()

$row = "" | Select vc,path,cluster,wwn #

foreach ($vc in $list) {
if (($vc -eq 'vc01') -or ($vc -eq 'vc02')) {
    Connect-VIserver $vc -user $username -password $password
    write-host "Non-standalone hosts:" -foregroundcolor green
    $clusters = get-cluster

    foreach ($cluster in $clusters) {
       
        $path = @()
        $parent = Get-View $cluster.ExtensionData.ResourcePool
            While ($parent.parent){ 
                $parent = Get-View $parent.parent
                $path += $parent.Name
            }
            $path = "$path".split(" ")[1]
            write-host "$vc"
            write-host "$path"

            $esxihost = get-cluster $cluster | Get-VMHost | select -first 1
            $out = get-vmhost $esxihost | get-vmhosthba | get-scsilun | get-scsilunpath | Select -ExpandProperty SanID -unique -ErrorAction "SilentlyContinue"

            write-host "$cluster"
            write-host "$out"
            write-host " "
           
            $row.vc = $vc
            $row.path = $path
            $row.cluster = $cluster
            $row.wwn = $out
            $report += $row

    }
####################
write-host "Standalone hosts:" -foregroundcolor green
#TM hosts not in cluster
$hostlist = Get-VMHost |where{$_.ExtensionData.Parent.Type -ne "ClusterComputeResource"}

$path = @()
foreach ($host1 in $hostlist) {
    $out = get-vmhost $host1 | get-vmhosthba | get-scsilun | get-scsilunpath | Select -ExpandProperty SanID -unique -ErrorAction "SilentlyContinue"
    $path = @($host1.Name) 
    $parent = Get-View $host1.ExtensionData.Parent
 
    While ($parent.parent){
        $parent = Get-View $parent.parent   
        if("Datacenters","host" -notcontains $parent.Name){
            $path += $parent.Name   
        }
     $path1 = "$path".split(" ")[1]    
    }
    write-host "$vc"
    write-host "$path1"
    write-host "$host1"
    write-host "$out"  
    write-host " "
    $row.vc = $vc
    $row.path = $path1
    $row.cluster = $host1
    $row.wwn = $out
    $report += $row
}
Disconnect-VIServer * -Confirm:$False

} else {
Connect-VIserver $vc -user $username -password $password
$clusters=get-cluster
foreach ($cluster in $clusters) {

$datacenter = get-datacenter
write-host "$datacenter"
$esxihost = get-cluster $cluster | Get-VMHost | select -first 1
$out = get-vmhost $esxihost | get-vmhosthba | get-scsilun | get-scsilunpath | Select -ExpandProperty SanID -unique -ErrorAction "SilentlyContinue"

write-host "$cluster"
write-host "$out"
write-host " "

$row.vc = $vc
$row.path = $datacenter
$row.cluster = $cluster
$row.wwn = $out
$report += $row
Disconnect-VIServer * -Confirm:$False

$report | Export-Csv ESXiStorageWWN.csv -NoTypeInformation -UseCulture

}}}

 

The powercli output:

1.PNG

This is the excel output I am looking for

2.PNG


Viewing all articles
Browse latest Browse all 232894

Trending Articles