VMware Cloud Community
ranjitcool
Hot Shot
Hot Shot

How do i grab one object in an array?

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

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
1 Reply
mattboren
Expert
Expert

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.

0 Kudos