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
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?
$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
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-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
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)
Datacenter | VMHost | Datastore | Folder | Templates |
MyDataCenter1 | Host1 | Datastore1 | Folder1 | Template1 |
Host2 | Datastore2 | Folder2 | Template2 |
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
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
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?
$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
Perfect Guru...Thanks a lot. this is what I was looking for