过滤powerCli命令的输出仅具有其中的一部分

发布于 2025-02-10 01:35:03 字数 489 浏览 4 评论 0原文

命令的输出是:

PS /root> Get-VM -Name alex-deploy2-000638 | Get-Harddisk

CapacityGB      Persistence                                                    Filename
----------      -----------                                                    --------
60.000          Persistent           …1] alex-deploy2-000638/alex-deploy2-000638_2.vmdk

我需要始终在 /

alex-deploy2-000638_2.vmdk

是否有一种过滤输出的方法之后的最后一部分,以切割所有不是disk-name.vmdk的所有内容?

The output of the command is:

PS /root> Get-VM -Name alex-deploy2-000638 | Get-Harddisk

CapacityGB      Persistence                                                    Filename
----------      -----------                                                    --------
60.000          Persistent           …1] alex-deploy2-000638/alex-deploy2-000638_2.vmdk

I need to always have the last part after the /

alex-deploy2-000638_2.vmdk

Is there a way to filter that output to cut everything else that is not disk-name.vmdk?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2025-02-17 01:35:03

首先,选择您感兴趣的属性(例如:文件名)。
然后,您可以使用split -path -leaf获取没有文件夹的文件名。

由于您的Get-HardDisk命令可以返回多个磁盘,因此我在最后一部分中包含了foreach,以确保其与单个磁盘和多个磁盘一起使用。

(Get-VM -Name alex-deploy2-000638 | Get-Harddisk).FileName  | % {$_ | Split-Path -Leaf}

First, select the property you are interested in (eg: FileName).
Then, you can use Split-Path -Leaf to get the filename without the folder.

Since your Get-HardDisk command can return multiple disks, I included a Foreach for the last part, to make sure it work with a single disk and multiple disks.

(Get-VM -Name alex-deploy2-000638 | Get-Harddisk).FileName  | % {$_ | Split-Path -Leaf}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文