Hello,
I am looking for a way to pull simple VM stats (vCPU, Memory Allocated, Disk Allocated), I have the following which works partly:
Get-VM |
Select Name,@{N='VMHost';E={$_.VMHost.Name}},
NumCpu,MemoryGB,UsedSpaceGB |
Export-Csv report.csv -NoTypeInformation -UseCulture
This pulls the UsedSpaceGB and for this report I am only concerned with allocatedGB for the disks as my storage policy is N+1, so it is doubling the disks sizes and I think also adding the memory pagefile back to the ammount? So I would really just like to see the sum of the disks assigned to the VMs instead. Is this doable?
Finally I need to also pull the TAG from the category "CN" on each machine into this report. There should only be 1 TAG assigned in this category on each VM (if at all, it could also not have one which is fine to be returned NULL). How would I do this in the same report?
ED7
Is the following code providing a property that shows the allocated diskspace as you want to see it?
And is the tag reported?
Get-VM |
Select Name, ProvisionedSpaceGB,UsedSpaceGB,
@{N='FileSizeGB';E={
[math]::Round(($_.Extensiondata.LayoutEx.File | Measure-Object -Property Size -Sum).Sum/1GB,2)}},
@{N='Tag';E={(Get-TagAssignment -Category CN -Entity $_ ).Tag.Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Still doubling it for all disks. Here is an example output from a machine that has a single 50GB disk and 4GB of memory assigned:
Name : CNdc02
ProvisionedSpaceGB : 104.20561847463250160217285156
UsedSpaceGB : 104.20561847463250160217285156
FileSizeGB : 104.21
Tag :
Also tags don't seem to be showing up on this one that I assigned a tag to:
Name : librenms
ProvisionedSpaceGB : 1032.1661687931045889854431152
UsedSpaceGB : 1032.1661681588739156723022461
FileSizeGB : 1032.17
Tag :
See screenshot
Not sure how that storage issue can be fixed.
On the Tag, which seems to be missing from the output.
Can you check what the following returns?
$vm = Get-VM -Name <enter-name>
Write-Host "NoCategory"
Get-TagAssignment -Entity $vm
Write-Host "With Category"
Get-TagAssignment -Entity $vm -Category CN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK. I assume I can just divide the total by 2 since our only storage policy is N+1 and then subtract the allocated memory from the total as well. Here is the output from the new code for the tag:
PS C:\Powershellscripts> .\GetVMs.ps1
NoCategory
Get-TagAssignment : 10/24/2018 10:09:59 AM Get-TagAssignment There is an error in the XML document.
At C:\Powershellscripts\GetVMs.ps1:5 char:1
+ Get-TagAssignment -Entity $vm
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTag
Assignment
With Category
Get-TagAssignment : 10/24/2018 10:09:59 AM Get-TagAssignment Value cannot be null.
Parameter name: collection
At C:\Powershellscripts\GetVMs.ps1:9 char:1
+ Get-TagAssignment -Entity $vm -Category CN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTag
Assignment
That is strange. Looks a bit like some of the bugs in the older Tag related cmdlets.
Which PowerCLI version are you using?
In the newer PowerCLI versions several of the Tag related cmdlet bugs were fixed, and they now all use the REST API.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> Get-PowerCLIVersion
WARNING: The cmdlet "Get-PowerCLIVersion" is deprecated. Please use the 'Get-Module' cmdlet instead.
PowerCLI Version
----------------
VMware PowerCLI 10.1.0 build 8346946
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component PowerCLI Component 10.1 build 8377811
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 10.1 build 8344055
I am running this against a vCenter 6.0 Appliance in this case if that matters.
I remember one instance where someone had to downgrade to PowerCLI 6.5.1 to get it working with vCenter 5.5U3.
See https://www.reddit.com/r/vmware/comments/9dt4zv/powercli_gettagassignment_broken_with_vcenter_55u3/
An alternative could be to use my rCisTag module till your migratation to vCenter 6.5 is completed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference