过滤powerCli命令的输出仅具有其中的一部分
命令的输出是:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,选择您感兴趣的属性(例如:
文件名
)。然后,您可以使用
split -path -leaf
获取没有文件夹的文件名。由于您的
Get-HardDisk
命令可以返回多个磁盘,因此我在最后一部分中包含了foreach
,以确保其与单个磁盘和多个磁盘一起使用。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 aForeach
for the last part, to make sure it work with a single disk and multiple disks.