public/New-VexaInventory.ps1
function New-VexaInventory { [CmdLetBinding()] param ( [string] $Server, [string] $Path ) $CluProps = . "$PSScriptRoot\..\properties\ClusterComputeResource.ps1" $VMHostProps = . "$PSScriptRoot\..\properties\HostSystem.ps1" $CluViewList = Get-View -Server $VIServer -ViewType "ClusterComputeResource" -Property $CluProps $DcViewList = Get-View -Server $VIServer -ViewType "Datacenter" $VMHostViewList = Get-View -Server $VIServer -ViewType "HostSystem" -Property $VMHostProps $ServiceInstanceParams = @{ Id = 'ServiceInstance' Server = $VIServer Property = 'Content.ViewManager','Content.RootFolder' } $ServiceInstance = Get-View @ServiceInstanceParams $ViewMgr = Get-View -Id $ServiceInstance.Content.ViewManager $DcList = foreach ($DcView in $DcViewList) { $ContView = $ViewMgr.CreateContainerView($DcView.MoRef, $null, $true) $ContViewObj = Get-View -Id $ContView $Children = $ContViewObj.View.ForEach({$_.ToString()}) [VexaDatacenter]::new($DcView, $Children) } $CluList = foreach ($CluView in $CluViewList) { [VexaClusterComputeResource]::new($CluView) } $VMHostList = foreach ($VMHostView in $VMHostViewList) { [VexaHostSystem]::new($VMHostView) } $Inventory = @{ ClusterComputeResource = $CluList Datacenter = $DcList HostSystem = $VMHostList VIServer = [VexaVIServer]::new($global:DefaultVIServers.Where({$_.Name -eq $VIServer})[0]) } if ($Path){ $Inventory | Export-Clixml -Path $Path -Depth 10 } else { $Inventory } } |