Difference between revisions of "Script Extracts and Examples (PowerCLI)"

Jump to navigation Jump to search
→‎Script Extracts: Added "ESX Datastore to LUN Mapping (ESX4)"
m (→‎ESX Log Tail: formatting)
(→‎Script Extracts: Added "ESX Datastore to LUN Mapping (ESX4)")
Line 740: Line 740:
</source>
</source>


=== ESX Datastore to LUN Mapping ===
=== ESX Datastore to LUN Mapping (ESX3) ===
Its bizarrely difficult to be able to map VMware presented datastore names to the underlying LUN's, despite the fact that its readily available via the VI Client.  The following was adapted from the work of ''Catman'' found in this forum thread - http://communities.vmware.com/thread/240466#240466.  As I expect to maybe want some of the other fields available during the working my notes from working through this are to be found [[Datastore to LUN Mapping (PowerCLI)|here]]
Its bizarrely difficult to be able to map VMware presented datastore names to the underlying LUN's, despite the fact that its readily available via the VI Client.  The following was adapted from the work of ''Catman'' found in this forum thread - http://communities.vmware.com/thread/240466#240466.  As I expect to maybe want some of the other fields available during the working my notes from working through this are to be found [[Datastore to LUN Mapping (PowerCLI)|here]]
<source lang="powershell">
<source lang="powershell">
Line 814: Line 814:
HP      HSV200          vmhba1:0:13  VMFS-DS-06
HP      HSV200          vmhba1:0:13  VMFS-DS-06
</pre>
</pre>
=== ESX Datastore to LUN Mapping (ESX4) ===
Produces a similar output to the above, but works for ESX4 servers.
<source lang="powershell">
function Get-DS-LUNs-v4 ($objESXs) {
    foreach ($cluster in (Get-View -ViewType "ClusterComputeResource")) {
      $vmhostsview = $cluster.host | % { Get-View $_ }
      $vmhostview  = $vmhostsview | Select -first 1
      $ScsiLuns    = $vmhostsview | % { $_.Config.StorageDevice.ScsiLun } | Select -unique *
      $UUIDs      = $ScsiLuns | Select -unique UUID
      $Datastores  = $vmhostsview | % { $_.Config.FileSystemVolume.MountInfo } | % { $_.Volume } | Select -Unique *
      $HostLUN    = $vmhostsview | % { $_.Config.StorageDevice.ScsiTopology.Adapter } | % { $_.Target | % { $_.LUN } } | Select -unique *
      foreach ($UUID in $UUIDs) {
        $Lun = $ScsiLuns | ? { $_.UUID -eq $UUID.UUID } | Select -first 1
        $objVolume              = "" | Select Datastore, Make, Model, LUN
        $objVolume.LUN      = ($HostLUN | ? { $_.ScsiLun -eq $Lun.Key } | select -unique LUN).LUN
        $objVolume.Make        = $Lun.Vendor
        $objVolume.Model        = $Lun.Model
        foreach ($vol in $Datastores) {
          if ($vol.extent | % { $_.diskname -eq $Lun.CanonicalName}) {
            $objVolume.Datastore  = $vol.Name
          }
        }
        $objVolume
      }
    }
}
</source>


=== Ping All VM's On ESX ===
=== Ping All VM's On ESX ===

Navigation menu