如何通过powercli检索VM的名称和路径 [英] How to retrieve the name and path of VM's through powercli

查看:93
本文介绍了如何通过powercli检索VM的名称和路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下脚本检索VM的 NAME和PATH ,并在 PATH 中获取我不想要的全长路径,我只需要在资源/



之后显示的路径是我的代码:

am using the below script to retrieve the NAME and PATH of the VM's and in the PATH am getting the full length path which i dont want it, i just need the path which is displaying after the Resources/

here is my code:

function Get-Path{
    param($Object)

    $path = $object.Name
    $parent = Get-View $Object.ExtensionData.ResourcePool
    while($parent){
        $path = $parent.Name + "/" + $path
        if($parent.Parent){
            $parent = Get-View $parent.Parent
        }
        else{$parent = $null}
    }
    $path
}

Get-VM | Select Name,
    @{N="Path";E={Get-Path -Object $_}}





输出:

http://s1065.photobucket.com/user/Izaz_Ahmed/media/Capture_zpsooe7ykac.jpg.html

推荐答案

Object)

Object)


path =
path =


object.Name
object.Name


这篇关于如何通过powercli检索VM的名称和路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆