使用 PowerCLI 检索符合我的标准的 VMWare 快照列表

Retrieving the list of VMWare snapshots using PowerCLI which fall under my criteria

我正在尝试使用 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 中的代码 returns 所有 VMWare 快照,包括具有 Uid 'XYZ' 的快照,这不应该发生。

如何修改代码?

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

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