VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to get folder, datastore, templates,vm hosts details

Hi,

I am unable to get the folder, datastore, templates,vm hosts details from my datacenter level.

I am just seeing datacenter name rest all are blank

Please help

get-datacenter | select Name,

get-vmhost | Select Name,

get-folder | Select Name,

Get-Datastore | Select Name,

get-template | Select Name | Export-Csv D:\inventory.csv -NoTypeInformation

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

It is still not clear to me what purpose such a list would offer.

None of the entries on the same row is guaranteed to have any relation with each other.

You mean something like this?

$dc = Get-Datacenter

$esx = Get-VMHost

$ds = Get-Datastore

$template = Get-Template

$folder = Get-Folder

$max = ($dc.Count,$esx.Count,$ds.Count,$template.Count,$folder.Count | Measure-Object -Maximum).Maximum


0..($max - 1) |

ForEach-Object -Process {

   New-Object PSObject -Property ([ordered]@{

   Datacenter = &{if($dc.Count -ge $_){$dc[$_]}}

   VMHost = &{if($esx.Count -ge $_){$esx[$_]}}

   Datastore = &{if($ds.Count -ge $_){$ds[$_]}}

   Template = &{if($template.Count -ge $_){$template[$_]}}

   Folder = &{if($folder.Count -ge $_){$folder[$_]}}

   })

} |

Export-Csv D:\inventory.csv -NoTypeInformation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

You can not concatenate several Select-Object outputs this way.
A better way is to use the PipelineVariable and pipe all Get cmdlets together.

The exception being the Folder part, for that we need to use a calculated property.

Something like this

Get-Datacenter -PipelineVariable dc |

Get-VMHost -PipelineVariable esx |

Get-Datastore -PipelineVariable ds |

Get-Template |

Select @{N='Datacenter';E={$dc.name}},

   @{N='VMHost';E={$esx.name}},

   @{N='Datastore';E={$ds.name}},

   @{N='Folder';E={(Get-View -Id $_.FolderId).Name}},

  Name |

Export-Csv D:\inventory.csv -NoTypeInformation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

Sorry, if question was confusing.

From my vCenter, I want to list all Folders, VMHosts, Templates, Datastores, to one csv file (same sheet with different columns)

     

DatacenterVMHostDatastoreFolderTemplates
MyDataCenter1Host1Datastore1Folder1Template1
Host2Datastore2Folder2Template2
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And how do you plan on combining that in the report? Per row?
There is no link between VMHost and folder (VM type) for example.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I want all these in different columns

I want this report for reference report while deploying templates. rather than logging into my vcenter and gather the datastore, folder etc details. I will use this report to create a answer file for deploying my template.

There would be many changes in the environment everyday, rather than going manual, i want this as a reference report.

Get-folder - all folder names in one column

get-datastore - all datastores names in one column

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It is still not clear to me what purpose such a list would offer.

None of the entries on the same row is guaranteed to have any relation with each other.

You mean something like this?

$dc = Get-Datacenter

$esx = Get-VMHost

$ds = Get-Datastore

$template = Get-Template

$folder = Get-Folder

$max = ($dc.Count,$esx.Count,$ds.Count,$template.Count,$folder.Count | Measure-Object -Maximum).Maximum


0..($max - 1) |

ForEach-Object -Process {

   New-Object PSObject -Property ([ordered]@{

   Datacenter = &{if($dc.Count -ge $_){$dc[$_]}}

   VMHost = &{if($esx.Count -ge $_){$esx[$_]}}

   Datastore = &{if($ds.Count -ge $_){$ds[$_]}}

   Template = &{if($template.Count -ge $_){$template[$_]}}

   Folder = &{if($folder.Count -ge $_){$folder[$_]}}

   })

} |

Export-Csv D:\inventory.csv -NoTypeInformation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Perfect Guru...Thanks a lot. this is what I was looking for Smiley Happy

0 Kudos