VMware Cloud Community
neil_armstrong7
Contributor
Contributor
Jump to solution

Get datastore info based on the Datacenter location

Hello,

I have written a powershell script to get the amount of free space avaliable in the datastores butthis is too high level

I need the information to be broken down as per the view of "Datastores" with the Virtual Centre

eg - my DataCentre folder look like

Teir 1

Datastores x -x-x-x-x-x-x

Teir 2

Datastores x-x-x-x-x-x-x-x

Teir 3

Datastores x-x-x-x-x-x-x-x

Can someone help please

0 Kudos
1 Solution

Accepted Solutions
DougBaer
Commander
Commander
Jump to solution

Absolutely. The problem has to do with the way pipelining works and the references that you're trying to use in the output. There are a few ways to handle this, and I think this may do what you want.

Get-Datacenter  |  Foreach-Object { $dc=$_; $dc | Get-Datastore | Select-Object @{name="DC Name"; expression={$dc.name}},Name,FreeSpaceMB,CapacityMB}

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23

View solution in original post

0 Kudos
8 Replies
DougBaer
Commander
Commander
Jump to solution

It might help if you give us an example of what you want.

Based on the subject, you can do something like Get-Datacenter | Get-Datastore | {your code here} to walk through the datastores per datacenter and do whatever you need, but I don't think what you want to do it quite that easy Smiley Happy

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
neil_armstrong7
Contributor
Contributor
Jump to solution

This is what I am doing so far :

      1. this is just to show you what my top level view looks like ###

get-datacenter -name *

Name Id

-


--

DEV Datacenter-datacenter-1039

TIER 3 Datacenter-datacenter-155

TIER 4 Datacenter-datacenter-158

###########

      1. This is what I thought would work ###

C:\> get-datacenter -name * |get-datastore

Name FreeSpaceMB CapacityMB

-


-


-


F_00165_T3_PAGE_002 28980 35584

F_00174_T3_PAGE_006 22858 30464

F_00114_T3_OS_001 146487 204544

F_00170_T3_OS_005 177228 204544

But as both of the view use "Name" I cannot format the table to show for example

TIER3 F_00165_T3_PAGE_002 28980 35584

TIER4 F_00175_T3_OS_001 146487 204544

Hope this explains a bit more

0 Kudos
neil_armstrong7
Contributor
Contributor
Jump to solution

Have uploaded more info

0 Kudos
DougBaer
Commander
Commander
Jump to solution

Absolutely. The problem has to do with the way pipelining works and the references that you're trying to use in the output. There are a few ways to handle this, and I think this may do what you want.

Get-Datacenter  |  Foreach-Object { $dc=$_; $dc | Get-Datastore | Select-Object @{name="DC Name"; expression={$dc.name}},Name,FreeSpaceMB,CapacityMB}

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
0 Kudos
DougBaer
Commander
Commander
Jump to solution

Absolutely. The problem has to do with the way pipelining works and the references that you're trying to use in the output. There are a few ways to handle this, and I think this may do what you want.

Get-Datacenter  |  Foreach-Object { $dc=$_; $dc | Get-Datastore | Select-Object @{name="DC Name"; expression={$dc.name}},Name,FreeSpaceMB,CapacityMB}

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
0 Kudos
DougBaer
Commander
Commander
Jump to solution

Absolutely. The problem has to do with the way pipelining works and the references that you're trying to use in the output. There are a few ways to handle this, and I think this may do what you want.

Get-Datacenter  |  Foreach-Object { $dc=$_; $dc | Get-Datastore | Select-Object @{name="DC Name"; expression={$dc.name}},Name,FreeSpaceMB,CapacityMB}

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
0 Kudos
neil_armstrong7
Contributor
Contributor
Jump to solution

That worked a treat

0 Kudos
harkamal
Expert
Expert
Jump to solution

Here you go..

Get-Datacenter | % { 

$dc = $_

$dc | Get-Datastore | FT +-AutoSize+ @{Label="DataCenter";Expression= {$dc.Name}}, Name, FreeSpaceMB 

}

#Click Helpfull or Correct button if that helped