Automation

 View Only
  • 1.  How much free space

    Posted Jul 29, 2013 09:19 PM

    I'm trying to add a line to this script and the line should also show VM's, cluster and how much free and used space on the LUN's. Also I will like the script to give me the name of the datastores.

    $report = foreach($esx in Get-VMHost){

        foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){

    if($hbaKey.Target){

    foreach($tgtKey in $hbaKey.Target){

                    foreach($lunKey in $tgtKey.Lun){

    $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter}

    $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun}

    Select-Object -InputObject $lun -Property @{N="Host";E={$esx.Name}},

    @{N="HBA";E={$hba.Device}},

    CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}

                    }

                }

            }

        }

    }

    $report | Export-Csv "C:\temp\lun-report.csv" -NoTypeInformation -UseCulture



  • 2.  RE: How much free space

    Posted Jul 30, 2013 12:03 AM

    Hi,

    The attached below would do your job, bold and italic lines are the ones I've added in:

    $report = foreach($esx in Get-VMHost){

        foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){

    if($hbaKey.Target){

    foreach($tgtKey in $hbaKey.Target){

                    foreach($lunKey in $tgtKey.Lun){

    $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter}

    $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun}

    $datastore = $esx | Get-Datastore | Where-Object {(%{$_.ExtensionData.Info.Vmfs.Extent} | %{$_.DiskName}) -match $lun.CanonicalName}

    Select-Object -InputObject $lun -Property @{N="Cluster";E={Get-Cluster -VMHost $esx | %{$_.Name}}},@{N="Host";E={$esx.Name}},@{N="Datastore";E={$datastore | %{$_.Name}}},@{N="FreeSpace";E={$datastore | %{$_.FreeSpaceGB}}},@{N="Capacity";E={$datastore | %{$_.CapacityGB}}},@{N="Virtual Machines";E={[string]::Join(",", (Get-VM -Datastore $datastore))}},

    @{N="HBA";E={$hba.Device}},

    CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}

                    }

                }

            }

        }

    }

    $report | Export-Csv "C:\temp\lun-report.csv" -NoTypeInformation -UseCulture



  • 3.  RE: How much free space

    Posted Jul 30, 2013 01:51 PM

    Thanks Skan070.



  • 4.  RE: How much free space

    Posted Jul 30, 2013 04:39 PM

    Hi Skan070,

    Can we add used space to the script? I left that out.

    Thanks,



  • 5.  RE: How much free space

    Posted Jul 30, 2013 11:02 PM

    Here you go: $report = foreach($esx in Get-VMHost){     foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){ if($hbaKey.Target){ foreach($tgtKey in $hbaKey.Target){                 foreach($lunKey in $tgtKey.Lun){ $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter} $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun} $datastore = $esx | Get-Datastore | Where-Object {(%{$_.ExtensionData.Info.Vmfs.Extent} | %{$_.DiskName}) -match $lun.CanonicalName} $freespace = $datastore | %{$_.FreeSpaceGB} $capacity = $datastore | %{$_.CapacityGB} Select-Object -InputObject $lun -Property @{N="Cluster";E={Get-Cluster -VMHost $esx | %{$_.Name}}},@{N="Host";E={$esx.Name}},@{N="Datastore";E={$datastore | %{$_.Name}}},@{N="Free Space (GB)";E={$freespace}},@{N="Capacity (GB)";E={$capacity}},@{N="Used Space (GB)";E={$capacity - $freespace}},@{N="Virtual Machines";E={[string]::Join(",", (Get-VM -Datastore $datastore))}}, @{N="HBA";E={$hba.Device}}, CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}                 }             }         }     } } $report | Export-Csv "C:\temp\lun-report.csv" -NoTypeInformation -UseCulture



  • 6.  RE: How much free space

    Posted Jul 31, 2013 12:15 AM

    It errored out. Below is the original one without the "Used Space Comment" Maybe there was a typo when you made the changes.

    $report = foreach($esx in Get-VMHost){

        foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){

    if($hbaKey.Target){

    foreach($tgtKey in $hbaKey.Target){

                    foreach($lunKey in $tgtKey.Lun){

    $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter}

    $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun}

    $datastore = $esx | Get-Datastore | Where-Object {(%{$_.ExtensionData.Info.Vmfs.Extent} | %{$_.DiskName}) -match $lun.CanonicalName}

    Select-Object -InputObject $lun -Property @{N="Cluster";E={Get-Cluster -VMHost $esx | %{$_.Name}}},@{N="Host";E={$esx.Name}},@{N="Datastore";E={$datastore | %{$_.Name}}},@{N="FreeSpace";E={$datastore | %{$_.FreeSpaceGB}}},@{N="Capacity";@{N="Used Space (GB)";E={$datastore | %{$_.CapacityGB}}},@{N="Virtual Machines";E={[string]::Join(",", (Get-VM -Datastore $datastore))}},

    @{N="HBA";E={$hba.Device}},

    CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}

                    }

                }

            }

        }

    }

    $report | Export-Csv "C:\temp\CF03-report.csv" -NoTypeInformation -UseCulture



  • 7.  RE: How much free space

    Posted Aug 01, 2013 01:58 AM

    This should do, just tested and it didn't produce any errors. $report = foreach($esx in Get-VMHost){     foreach($hbaKey in ($esx.Extensiondata.Config.StorageDevice.ScsiTopology.Adapter | where {$_.Adapter -like "*FibreChannelHba*"})){ if($hbaKey.Target){ foreach($tgtKey in $hbaKey.Target){                 foreach($lunKey in $tgtKey.Lun){ $hba = $esx.Extensiondata.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hbaKey.Adapter} $lun = $esx.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key -eq $lunKey.ScsiLun} $datastore = $esx | Get-Datastore | Where-Object {(%{$_.ExtensionData.Info.Vmfs.Extent} | %{$_.DiskName}) -match $lun.CanonicalName} $freespace = $datastore | %{$_.FreeSpaceGB} $capacity = $datastore | %{$_.CapacityGB} $usedspace = $capacity - $freespace Select-Object -InputObject $lun -Property @{N="Cluster";E={Get-Cluster -VMHost $esx | %{$_.Name}}},@{N="Host";E={$esx.Name}},@{N="Datastore";E={$datastore | %{$_.Name}}},@{N="FreeSpace (GB)";E={$freespace}},@{N="Capacity (GB)";E={$capacity}},@{N="Used Space (GB)";E={$usedspace}},@{N="Virtual Machines";E={[string]::Join(",", (Get-VM -Datastore $datastore))}}, @{N="HBA";E={$hba.Device}}, CanonicalName,DisplayName,@{N="LUN";E={$lunKey.Lun}}                 }             }         }     } } $report | Export-CSV "C:\temp\CF03-report.csv" -NoTypeInformation -UseCulture