Automation

 View Only
  • 1.  How do i grab one object in an array?

    Posted Aug 09, 2011 10:06 PM

    Hello,

    When i say Get-Datacenter, it displays all the info such as,

    ParentFolderId : Folder-group-d1
    ParentFolder   : Datacenters
    CustomFields   : {}
    ExtensionData  : VMware.Vim.Datacenter
    Id             : Datacenter-datacenter-21
    Name           : NAMEOFDC
    Uid            : a uid

    Now i only want to get the NAME info in a variable for later display. How do i get that.

    I tried

    Get-datacenter {@_Name} but error.

    Please help.

    Thanks

    RJ



  • 2.  RE: How do i grab one object in an array?

    Posted Aug 09, 2011 11:22 PM

    Hello, ranjitcool-

    To grab the name when you get more than one item returned, you could use a Foreach-Object loop, like:

    Get-Datacenter | %{
       
    $strDCName = $_.Name
       
    ## ... do something with $strDCName here ...
    } ## end foreach-object

    Enjoy.