@@ -55,9 +55,14 @@ function Invoke-AsBuiltReport.VMware.vSphere {
5555 # region Generate vSphere report
5656 if ($vCenter ) {
5757 # Check logged in user has sufficient privileges to generate an As Built Report
58- Write-PScriboMessage ' Checking user privileges.'
59- $UserPermission = Get-VIPermission | Where-Object {$_.Principal -eq $vCenter.User }
60- $UserRole = Get-VIRole - Name $UserPermission.Role
58+ Write-PScriboMessage ' Checking vCenter user privileges.'
59+ Try {
60+ $UserPermission = Get-VIPermission | Where-Object {$_.Principal -eq $vCenter.User }
61+ $AuthMgr = Get-View $ ($vCenter.ExtensionData.Content.AuthorizationManager )
62+ $UserRole = $AuthMgr.RoleList | Where-Object {$_.Name -eq $ ($UserPermission.Role )}
63+ } Catch {
64+ Write-PScriboMessage ' Unable to obtain vCenter user privileges.'
65+ }
6166
6267 # Create a lookup hashtable to quickly link VM MoRefs to Names
6368 # Exclude VMware Site Recovery Manager placeholder VMs
@@ -195,7 +200,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
195200 ' MemberType' = ' NoteProperty'
196201 }
197202 # region vCenter Server Detail
198- if ($UserRole.PrivilegeList -contains ' Global.Licenses' ) {
203+ if ($UserRole.Privilege -contains ' Global.Licenses' ) {
199204 $vCenterLicense = Get-License - vCenter $vCenter
200205 Add-Member @MemberProps - Name ' Product' - Value $vCenterLicense.Product
201206 Add-Member @MemberProps - Name ' License Key' - Value $vCenterLicense.LicenseKey
@@ -299,7 +304,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
299304 # endregion vCenter Server Historical Statistics
300305
301306 # region vCenter Server Licensing
302- if ($UserRole.PrivilegeList -contains ' Global.Licenses' ) {
307+ if ($UserRole.Privilege -contains ' Global.Licenses' ) {
303308 Section - Style Heading3 ' Licensing' {
304309 $Licenses = Get-License - Licenses | Select-Object Product, @ {L = ' License Key' ; E = { ($_.LicenseKey ) } }, Total, Used, @ {L = ' Available' ; E = { ($_.total ) - ($_.Used ) } }, Expiration - Unique
305310 if ($Healthcheck.vCenter.Licensing ) {
@@ -396,8 +401,14 @@ function Invoke-AsBuiltReport.VMware.vSphere {
396401 $TagInfo = foreach ($Tag in $Tags ) {
397402 [PSCustomObject ] @ {
398403 ' Tag' = $Tag.Name
399- ' Description' = $Tag.Description
400- ' Category' = $Tag.Category
404+ ' Description' = Switch ($Tag.Description ) {
405+ ' ' { ' None' }
406+ default { $Tag.Description }
407+ }
408+ ' Category' = Switch ($Tag.Category ) {
409+ ' ' { ' None' }
410+ default { $Tag.Category }
411+ }
401412 }
402413 }
403414 $TableParams = @ {
@@ -418,8 +429,14 @@ function Invoke-AsBuiltReport.VMware.vSphere {
418429 $TagCategoryInfo = foreach ($TagCategory in $TagCategories ) {
419430 [PSCustomObject ] @ {
420431 ' Category' = $TagCategory.Name
421- ' Description' = $TagCategory.Description
422- ' Cardinality' = $TagCategory.Cardinality
432+ ' Description' = Switch ($TagCategory.Description ) {
433+ ' ' { ' None' }
434+ default { $TagCategory.Description }
435+ }
436+ ' Cardinality' = Switch ($TagCategory.Cardinality ) {
437+ ' ' { ' None' }
438+ default { $TagCategory.Cardinality }
439+ }
423440 }
424441 }
425442 $TableParams = @ {
@@ -457,7 +474,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
457474 # endregion vCenter Server Tag Assignments
458475
459476 # region VM Storage Policies
460- if ($UserRole.PrivilegeList -contains ' StorageProfile.View' ) {
477+ if ($UserRole.Privilege -contains ' StorageProfile.View' ) {
461478 $SpbmStoragePolicies = Get-SpbmStoragePolicy | Sort-Object Name
462479 if ($SpbmStoragePolicies ) {
463480 Section - Style Heading3 ' VM Storage Policies' {
@@ -1464,7 +1481,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
14641481 # endregion Cluster VM Overrides
14651482
14661483 # region Cluster VUM Baselines
1467- if ($UserRole.PrivilegeList -contains ' VcIntegrity.Updates.com.vmware.vcIntegrity.ViewStatus' ) {
1484+ if ($UserRole.Privilege -contains ' VcIntegrity.Updates.com.vmware.vcIntegrity.ViewStatus' ) {
14681485 if ($VUMConnection ) {
14691486 if (" Desktop" -eq $PSVersionTable.PsEdition ) {
14701487 $ClusterPatchBaselines = $Cluster | Get-PatchBaseline
@@ -1512,7 +1529,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
15121529 # endregion Cluster VUM Baselines
15131530
15141531 # region Cluster VUM Compliance (Advanced Detail Information)
1515- if ($UserRole.PrivilegeList -contains ' VcIntegrity.Updates.com.vmware.vcIntegrity.ViewStatus' ) {
1532+ if ($UserRole.Privilege -contains ' VcIntegrity.Updates.com.vmware.vcIntegrity.ViewStatus' ) {
15161533 if ($InfoLevel.Cluster -ge 4 -and $VumServer.Name ) {
15171534 if (" Desktop" -eq $PSVersionTable.PsEdition ) {
15181535 $ClusterCompliances = $Cluster | Get-Compliance
@@ -1819,7 +1836,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
18191836 ' InputObject' = $VMHostDetail
18201837 ' MemberType' = ' NoteProperty'
18211838 }
1822- if ($UserRole.PrivilegeList -contains ' Global.Licenses' ) {
1839+ if ($UserRole.Privilege -contains ' Global.Licenses' ) {
18231840 $VMHostLicense = Get-License - VMHost $VMHost
18241841 Add-Member @MemberProps - Name ' Product' - Value $VMHostLicense.Product
18251842 Add-Member @MemberProps - Name ' License Key' - Value $VMHostLicense.LicenseKey
@@ -1950,7 +1967,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
19501967 # endregion ESXi Host Profile Information
19511968
19521969 # region ESXi Host Image Profile Information
1953- if ($UserRole.PrivilegeList -contains ' Host.Config.Settings' ) {
1970+ if ($UserRole.Privilege -contains ' Host.Config.Settings' ) {
19541971 Section - Style Heading5 ' Image Profile' {
19551972 $installdate = Get-InstallDate
19561973 $esxcli = Get-EsxCli - VMHost $VMHost - V2 - Server $vCenter
@@ -2017,7 +2034,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
20172034 # endregion ESXi Host Syslog Configuration
20182035
20192036 # region ESXi Update Manager Baseline Information
2020- if ($UserRole.PrivilegeList -contains ' VcIntegrity.Updates.com.vmware.vcIntegrity.ViewStatus' ) {
2037+ if ($UserRole.Privilege -contains ' VcIntegrity.Updates.com.vmware.vcIntegrity.ViewStatus' ) {
20212038 if ($VumServer.Name ) {
20222039 if (" Desktop" -eq $PSVersionTable.PsEdition ) {
20232040 $VMHostPatchBaselines = $VMHost | Get-PatchBaseline
@@ -2053,7 +2070,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
20532070 # endregion ESXi Update Manager Baseline Information
20542071
20552072 # region ESXi Update Manager Compliance Information
2056- if ($UserRole.PrivilegeList -contains ' VcIntegrity.Updates.com.vmware.vcIntegrity.ViewStatus' ) {
2073+ if ($UserRole.Privilege -contains ' VcIntegrity.Updates.com.vmware.vcIntegrity.ViewStatus' ) {
20572074 if ($VumServer.Name ) {
20582075 if (" Desktop" -eq $PSVersionTable.PsEdition ) {
20592076 $VMHostCompliances = $VMHost | Get-Compliance
@@ -4158,7 +4175,7 @@ function Invoke-AsBuiltReport.VMware.vSphere {
41584175 # region Virtual Machine Detailed Information
41594176 # TODO: Test Tags
41604177 if ($InfoLevel.VM -ge 3 ) {
4161- if ($UserRole.PrivilegeList -contains ' StorageProfile.View' ) {
4178+ if ($UserRole.Privilege -contains ' StorageProfile.View' ) {
41624179 $VMSpbmConfig = Get-SpbmEntityConfiguration - VM ($VMs ) | Where-Object { $null -ne $_.StoragePolicy }
41634180 } else {
41644181 Write-PScriboMessage " Insufficient user privileges to report VM storage policies. Please ensure the user account has the 'Storage Profile > View' privilege assigned."
0 commit comments