【问题标题】:Get LUN paths for esxi host using powercli使用 powercli 获取 esxi 主机的 LUN 路径
【发布时间】:2023-02-10 21:58:54
【问题描述】:

我正在寻找获取路径详细信息

我正在尝试使用下面的代码来做到这一点,但出现了一些错误

$vkcpw = Get-Content E:\Encrypted_Password\vkcpw.txt | ConvertTo-SecureString -Key (Get-Content E:\Encrypted_Password\V-center_aes.key)
$vcentercredential   = New-Object System.Management.Automation.PsCredential("",$vkcpw)
Connect-VIServer -server 192.168.1.3 -Credential $vcentercredential

function Get-LUNPathState {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $true,Position = 0,HelpMessage = 'ESXi Host',ValueFromPipeline = $true)]
        [Alias('Name')]
        [ValidateNotNullorEmpty()]
        $VMhosts
    )

    $ReportLunPathState = @()
    $i = 0

    try
    {
        ForEach ($VMHost in $VMhosts) {
            $i++
            $VMHostDatastores = Get-Datastore
            $VMHostScsiLuns = $VMHost | Get-ScsiLun -LunType disk


            ForEach ($VMHostScsiLun in $VMHostScsiLuns) {
                $VMHostScsiLunPaths = $VMHostScsiLun | Get-ScsiLunPath
                $ReportLunPathState += ($VMHostScsiLunPaths | Measure-Object) | Select-Object `
                -Property @{N = 'Hostname'; E = {$VMHost.Name}}, `
                @{N = 'Datastore'; E = {$VMHostDatastores | Where-Object -FilterScript {($_.extensiondata.info.vmfs.extent | ForEach-Object -Process {$_.diskname}) -contains $VMHostScsiLun.CanonicalName}| Select-Object -ExpandProperty name}}, `
                @{N = 'CanonicalName'; E = {$VMHostScsiLun.CanonicalName}}, `
                @{N = '# of Paths'; E = {$_.Count}}, `
                @{N = 'Path State'; E = {$VMHostScsiLunPaths.State}}
            }
        }
    
}

Get-LUNPathState -VMhosts 'gen35'

我收到错误

Get-ScsiLun     Get-ScsiLun does not accept string input through pipeline. The string 'gen35' was ignored.  

请让我知道这里有什么问题。或者我在获取以下数据时做错了

【问题讨论】:

    标签: powershell


    【解决方案1】:

    错误消息说明了一切 - 不要尝试将输入通过管道传输到 Get-ScsiLun,它将无法将其绑定到正确的参数。

    更改此行:

    $VMHostScsiLuns = $VMHost | Get-ScsiLun -LunType disk
    

    到:

    $VMHostScsiLuns = Get-ScsiLun -VMHost $VMHost -LunType disk
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-25
      • 2019-02-23
      • 1970-01-01
      • 2021-05-07
      • 2022-12-04
      • 1970-01-01
      • 2013-03-14
      • 2018-05-10
      相关资源
      最近更新 更多