Export LUN IDs with Path Selection Policy

Featured

In this post we are sharing a PowerCLI script that we used to export a list of LUNs attached to ESXi hosts in a cluster along with the details of Path Selection Policy selected for the LUN and CommandsToSwitchPath parameter set for the LUNs.

Script was tested on below versions:

  • PowerCLI version 11.5.0 build 14912921
  • vSphere 6.7U3

Script:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$cred = Get-Credential
Connect-VIServer vCenter_IP/FQDN -Credential $cred

$getCluster = Get-Cluster -Name "Cluster_Name"
$getESXis = $getCluster | Get-VMHost
$printluns=@()

foreach ($getESXi in $getESXis)
{
    $getLUNsforESXi = Get-VMhost $getESXi | Get-ScsiLun -LunType disk | Select VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath
    $printluns = $printluns + $getLUNsforESXi
}

$printluns | Export-Csv C:\users\Administrator\Desktop\PathtoSaveFile.csv -NoTypeInformation 

Disconnect-VIServer -Confirm:$false

Just replace the vCenter_Server_IP_Address/FQDN, Cluster_Name and Path of CSV File and run the script to generate a report of LUNs mapped to all ESXi hosts in a vSphere cluster in your environment. BOOM!!

Happy Scripting!!

Export vRA 7.6 Reservation Details

In this post we are sharing a PowerShell script which uses PowervRA Module to export a list of vRealize Automation 7.6 Reservations along with their respective usage.

Script was tested on below versions:

  • PowervRA 3.7.0
  • PowerShell 5.1 or later

Script:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$cred = Get-Credential
Connect-vRAServer -Server 'vRA_FQDN' -Username $cred.UserName -Password $cred.Password -Tenant "Tenant_Name" -IgnoreCertRequirements
$BGReserves = Get-vRAReservation | Select CreatedDate, Name, TenantId, ExtensionData
$fetchVMDetails= Get-vRAResource | where {$_.ResourceType -eq "Infrastructure.Virtual"}
$output = @()
    foreach($BGReserve in $BGReserves)
    {

        $ReserveVMDetails = ($fetchVMDetails | where {$_.Data.MachineReservationName -eq $BGReserve.name}).Data  | Select MachineName, MachineMemory, MachineStorage
    foreach ($ReserveVMDetail in $ReserveVMDetails)
    {
        $MachineQuotaUsed = $MachineQuotaUsed + 1
        $MemoryUsedinMB = $MemoryUsedinMB + $ReserveVMDetail.MachineMemory
        $StorageUsedinGB = $StorageUsedinGB + $ReserveVMDetail.MachineStorage
    }
    $MemoryUsedinGB = $MemoryUsedinMB/1024
        $fetchReserveDetails = $BGReserve.ExtensionData.entries
        $fetchQuotavalue = ($fetchReserveDetails |  where {$_.key -eq "machineQuota"}).value.value
        $BGReserve | Add-Member -NotePropertyName MachineQuota -NotePropertyValue $fetchQuotavalue
        $fetchMemoryReserve = (($fetchReserveDetails | where {$_.key -eq "reservationMemory"}).value.values.entries | where {$_.key -eq "memoryReservedSizeMb"}).value.value/1024
        $BGReserve | Add-Member -NotePropertyName MemoryReservedinGB -NotePropertyValue $fetchMemoryReserve
        $fetchStorageReserve = (($fetchReserveDetails | where {$_.key -eq "reservationStorages"}).value.items.values.entries | where {$_.key -eq "storageReservedSizeGB"}).value.value
        $BGReserve | Add-Member -NotePropertyName StorageReservedinGB -NotePropertyValue $fetchStorageReserve
        $MachineQuotaAllocated = $MachineQuotaAllocated + $fetchQuotavalue
        $BGReserve | Add-Member -NotePropertyName MachinesAllocated -NotePropertyValue $MachineQuotaUsed
        $MemoryAllocatedinGB = $MemoryAllocatedinGB + $fetchMemoryReserve
        $BGReserve | Add-Member -NotePropertyName MemoryAllocatedinGB -NotePropertyValue $MemoryUsedinGB
        $StorageAllocatedinGB = $StorageAllocatedinGB + $fetchStorageReserve
        $BGReserve | Add-Member -NotePropertyName StorageAllocatedinGB -NotePropertyValue $StorageUsedinGB
        $MachineQuotaAllocated = 0
        $MemoryAllocatedinGB = 0
        $StorageAllocatedinGB = 0
        $MemoryUsedinMB = 0
        $MemoryUsedinGB = 0
        $StorageUsedinGB = 0
        $MachineQuotaUsed = 0
    }

$output = $BGReserves | Select Name, CreatedDate, TenantId, MachineQuota, MachinesAllocated, MemoryReservedinGB, MemoryAllocatedinGB, StorageReservedinGB, StorageAllocatedinGB
$output | FT -AutoSize -Wrap

$output | Export-Csv "Path_To_Target.csv" -NoTypeInformation

Disconnect-vRAServer -Confirm:$false

Just replace the vRA_FQDN, Tenant_Name, Path_To_Target.csv and TenantAdmin Credentials to run the script & to generate a report of vRealize Automation 7.6 Reservations in your environment. BOOM!!

Happy Scripting!!

Export vRA 7.6 Reservation Details

In this post we are sharing a PowerShell script which uses PowervRA Module to export a list of vRealize Automation 7.6 Reservations along with their respective usage.

Script was tested on below versions:

  • PowervRA 3.7.0
  • PowerShell 5.1 or later

Script:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$cred = Get-Credential
Connect-vRAServer -Server 'vRA_FQDN' -Username $cred.UserName -Password $cred.Password -Tenant "Tenant_Name" -IgnoreCertRequirements
$BGReserves = Get-vRAReservation | Select CreatedDate, Name, TenantId, ExtensionData
$fetchVMDetails= Get-vRAResource | where {$_.ResourceType -eq "Infrastructure.Virtual"}
$output = @()
    foreach($BGReserve in $BGReserves)
    {

        $ReserveVMDetails = ($fetchVMDetails | where {$_.Data.MachineReservationName -eq $BGReserve.name}).Data  | Select MachineName, MachineMemory, MachineStorage
    foreach ($ReserveVMDetail in $ReserveVMDetails)
    {
        $MachineQuotaUsed = $MachineQuotaUsed + 1
        $MemoryUsedinMB = $MemoryUsedinMB + $ReserveVMDetail.MachineMemory
        $StorageUsedinGB = $StorageUsedinGB + $ReserveVMDetail.MachineStorage
    }
    $MemoryUsedinGB = $MemoryUsedinMB/1024
        $fetchReserveDetails = $BGReserve.ExtensionData.entries
        $fetchQuotavalue = ($fetchReserveDetails |  where {$_.key -eq "machineQuota"}).value.value
        $BGReserve | Add-Member -NotePropertyName MachineQuota -NotePropertyValue $fetchQuotavalue
        $fetchMemoryReserve = (($fetchReserveDetails | where {$_.key -eq "reservationMemory"}).value.values.entries | where {$_.key -eq "memoryReservedSizeMb"}).value.value/1024
        $BGReserve | Add-Member -NotePropertyName MemoryReservedinGB -NotePropertyValue $fetchMemoryReserve
        $fetchStorageReserve = (($fetchReserveDetails | where {$_.key -eq "reservationStorages"}).value.items.values.entries | where {$_.key -eq "storageReservedSizeGB"}).value.value
        $BGReserve | Add-Member -NotePropertyName StorageReservedinGB -NotePropertyValue $fetchStorageReserve
        $MachineQuotaAllocated = $MachineQuotaAllocated + $fetchQuotavalue
        $BGReserve | Add-Member -NotePropertyName MachinesAllocated -NotePropertyValue $MachineQuotaUsed
        $MemoryAllocatedinGB = $MemoryAllocatedinGB + $fetchMemoryReserve
        $BGReserve | Add-Member -NotePropertyName MemoryAllocatedinGB -NotePropertyValue $MemoryUsedinGB
        $StorageAllocatedinGB = $StorageAllocatedinGB + $fetchStorageReserve
        $BGReserve | Add-Member -NotePropertyName StorageAllocatedinGB -NotePropertyValue $StorageUsedinGB
        $MachineQuotaAllocated = 0
        $MemoryAllocatedinGB = 0
        $StorageAllocatedinGB = 0
        $MemoryUsedinMB = 0
        $MemoryUsedinGB = 0
        $StorageUsedinGB = 0
        $MachineQuotaUsed = 0
    }

$output = $BGReserves | Select Name, CreatedDate, TenantId, MachineQuota, MachinesAllocated, MemoryReservedinGB, MemoryAllocatedinGB, StorageReservedinGB, StorageAllocatedinGB
$output | FT -AutoSize -Wrap

$output | Export-Csv "Path_To_Target.csv" -NoTypeInformation

Disconnect-vRAServer -Confirm:$false

Just replace the vRA_FQDN, Tenant_Name, Path_To_Target.csv and TenantAdmin Credentials to run the script & to generate a report of vRealize Automation 7.6 Reservations in your environment. BOOM!!

Happy Scripting!!

Export LUN IDs with Path Selection Policy

Featured

In this post we are sharing a PowerCLI script that we used to export a list of LUNs attached to ESXi hosts in a cluster along with the details of Path Selection Policy selected for the LUN and CommandsToSwitchPath parameter set for the LUNs.

Script was tested on below versions:

  • PowerCLI version 11.5.0 build 14912921
  • vSphere 6.7U3

Script:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$cred = Get-Credential
Connect-VIServer vCenter_IP/FQDN -Credential $cred

$getCluster = Get-Cluster -Name "Cluster_Name"
$getESXis = $getCluster | Get-VMHost
$printluns=@()

foreach ($getESXi in $getESXis)
{
    $getLUNsforESXi = Get-VMhost $getESXi | Get-ScsiLun -LunType disk | Select VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath
    $printluns = $printluns + $getLUNsforESXi
}

$printluns | Export-Csv C:\users\Administrator\Desktop\PathtoSaveFile.csv -NoTypeInformation 

Disconnect-VIServer -Confirm:$false

Just replace the vCenter_Server_IP_Address/FQDN, Cluster_Name and Path of CSV File and run the script to generate a report of LUNs mapped to all ESXi hosts in a vSphere cluster in your environment. BOOM!!

Happy Scripting!!