Hi everyone, last few days I've been looking at some of the reporting needs we have and I've been asked if it's possible to combine inventory data (for example UsedSpaceGB) with our tag report..
Is it possible to combine two basic scripts or would it be best to keep them seperate then just manipulate the data in the likes of excel?
I've currently got this for tags after being helped out here
$objTemplate = @{
VM = ''
}
(Get-TagCategory).Name | Sort-Object | ForEach-Object -Process {
$objTemplate.Add($_,'')
}
Get-TagAssignment|
Group-Object -Property {$_.Entity.Name} |
ForEach-Object -Process {
$obj = $objTemplate.Clone()
$obj['VM'] = $_.Name
$_.Group | Group-Object -Property {$_.Tag.Category.Name} |
ForEach-Object -Process {
$cat = $_.Name
$vTag = $_.Group | Group-Object -Property {$_.Tag.Category.Name} |
ForEach-Object -Process {
$_.Group.Tag.Name
}
$obj[$cat] = (($vTag | Sort-Object) -join '|')
}
New-Object PSObject -Property $obj
} |
Export-Csv abc.csv -NoTypeInformation -UseCulture
and for the vm inventory, again came across the above here in the community
Get-VM |
Select-object Name,
@{N = 'vCenter'; E = {([system.uri]$_.ExtensionData.Client.ServiceUrl).Host}},
@{N='TagCategories';E={
$script:assigned = Get-TagAssignment -Entity $_
$script:assigned.Tag.Category.Name -join '|' }},
@{N = 'Tags'; E = {$script:assigned.Tag.Name -join '|'}},
PowerState, Notes, Guest, NumCpu, CoresPerSocket, MemoryMB, MemoryGB, VMHostId, VMHost,
Folder, Version, GuestId, UsedSpaceGB, ProvisionedSpaceGB |
Export-Csv vc_inv_basic.csv –NoTypeInformation -UseCulture
Just looking for some pointers.. thanks in advance.
Since the Entity property, returned from Get-TagAssignment, contains a full VirtualMachine .NET object, you can easily extract the UsedSpaceGB from there.
All the other properties in your second script can be done in the same way.
$objTemplate = @{
VM = ''
UsedSpaceGB = ''
}
(Get-TagCategory).Name | Sort-Object | ForEach-Object -Process {
$objTemplate.Add($_, '')
}
Get-TagAssignment |
where { $_.Entity.GetType().Name -eq 'VirtualMachineImpl' } |
Group-Object -Property { $_.Entity.Name } |
ForEach-Object -Process {
$obj = $objTemplate.Clone()
$obj['VM'] = $_.Name
$obj['UsedSpaceGB'] = $_.Group[0].Entity.UsedSpaceGB
$_.Group | Group-Object -Property { $_.Tag.Category.Name } |
ForEach-Object -Process {
$cat = $_.Name
$vTag = $_.Group | Group-Object -Property { $_.Tag.Category.Name } |
ForEach-Object -Process {
$_.Group.Tag.Name
}
$obj[$cat] = (($vTag | Sort-Object) -join '|')
}
New-Object PSObject -Property $obj
} |
Export-Csv abc.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The question is how you want to combine this.
Do you want a report per VM, including the UsedSpaceGB, which also shows which Tags are assigned to that VM.
Note that this will not show Tags that are not assigned to any VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc, that's a good question, I was just looking to see if I could combine the two as I've been asked if it's possible to show the VM name, tags for that VM and the amount of storage used by that VM. At the moment the the tag report shows the VM and then has a separate column for each tag as we've enforced standards to our build engineers with regards the categories and tags themselves..
The way I was going to do it just do a vlookup of sorts in excel to add that storage use but thought I would check first to see if there was a way I could pull it into one output... thanks.
Since the Entity property, returned from Get-TagAssignment, contains a full VirtualMachine .NET object, you can easily extract the UsedSpaceGB from there.
All the other properties in your second script can be done in the same way.
$objTemplate = @{
VM = ''
UsedSpaceGB = ''
}
(Get-TagCategory).Name | Sort-Object | ForEach-Object -Process {
$objTemplate.Add($_, '')
}
Get-TagAssignment |
where { $_.Entity.GetType().Name -eq 'VirtualMachineImpl' } |
Group-Object -Property { $_.Entity.Name } |
ForEach-Object -Process {
$obj = $objTemplate.Clone()
$obj['VM'] = $_.Name
$obj['UsedSpaceGB'] = $_.Group[0].Entity.UsedSpaceGB
$_.Group | Group-Object -Property { $_.Tag.Category.Name } |
ForEach-Object -Process {
$cat = $_.Name
$vTag = $_.Group | Group-Object -Property { $_.Tag.Category.Name } |
ForEach-Object -Process {
$_.Group.Tag.Name
}
$obj[$cat] = (($vTag | Sort-Object) -join '|')
}
New-Object PSObject -Property $obj
} |
Export-Csv abc.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, that's perfect!