【问题标题】:Retrieving the list of VMWare snapshots using PowerCLI which fall under my criteria使用 PowerCLI 检索符合我标准的 VMWare 快照列表
【发布时间】:2016-12-27 18:11:17
【问题描述】:

我正在尝试使用 PowerCLI 获取其 Uid 与“XYZ”不匹配的 VMWare 快照列表。

为此,我编写了以下代码。

$body +=echo ""`r`n""`r`n"-----Open VMware snapshots other than Uid 'XYZ'-----"`r`n""`r`n""
Get-VM | Get-snapshot | where {($_.Uid -notmatch 'XYZ')} |  ForEach-Object {
    $object=New-Object -TypeName PSObject -Property @{
        VM_Name = $_.VM
        Created = $_.Created
        Size = "$([math]::Round($_.SizeGB, 2)) GB"
        SnapshotName = $_.name
        Description = $_.extensiondata.description
                 }
    $body +=  $object | ft | out-string
    Write-Output $object    
    }

在 PowerCLI 中运行该代码会返回所有 VMWare 快照,包括 Uid 为“XYZ”的快照,这是不应该发生的。

如何修改代码?

【问题讨论】:

    标签: vmware vsphere powercli


    【解决方案1】:

    尝试在 Where-Object 比较中使用 -ne-notlike,因为看起来我们是在比较字符串而不是使用正则表达式。

    Get-VM | Get-snapshot | where {($_.Uid -notlike 'XYZ')} | ForEach-Object ...

    【讨论】:

    • 我使用了 -notlike,但得到了相同的响应
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多