VMware Cloud Community
silverain
Contributor
Contributor

Get-View on disk.Datastore: "Permission to perform this operation was denied. Required privilege 'System.Read'"

When trying to run this script:

$VC = Connect-VIServer localhost -Protocol https -User administrator -Password "#############"

## Our VMFS datastores use a standard naming convention.  This differentiates them from local storage and

##     templates.  Change the -Name parameter to match your naming conventions

$VMFS = Get-Datastore -refresh -Name "LUN???" | Sort-Object $_.Name

$report = @()                                         # blank data structure

$allvms = Get-Datacenter "Datacenter" | Get-VM | Sort-Object $_.Name          # I likes to sorts my datas

foreach ($vm in $allvms) {

     $vmview = $vm | Get-View                    # get-view to see details of the FM

     foreach($disk in $vmview.Storage.PerDatastoreUsage){      # Disks for the VM

             $dsview = (Get-View $disk.Datastore)                    # Datastore used by the disks

          $dsview.RefreshDatastoreStorageInfo()                    # refresh to get the latest data

        

          $vmview.Config.Name                              # Echo to the screen to show progress

          $row = "" | select VMNAME, DATASTORE, VMSIZE_MB, VMUSED_MB, PERCENT     # blank row

          $row.VMNAME = $vmview.Config.Name                         # Add the data to the row

          $row.DATASTORE = $dsview.Name

          $row.VMSIZE_MB = (($disk.Committed+$disk.Uncommitted)/1024/1024)

          $row.VMUSED_MB = (($disk.Committed)/1024/1024)

          $row.PERCENT = [int](($row.VMUSED_MB / $row.VMSIZE_MB)*100)

          $report += $row                                                                  # Add the row to the structure

   }

}

$report | Export-Csv "C:\temp\vm_dss.csv" -NoTypeInformation     # dump the report to .csv

$DSReport = @()                         # blank data structure for datastore information

foreach ($LUN in $VMFS) {        

     $VMSizeSum = 0                    # We will sum the data from the previous report for this LUN

     $LUN.Name                         # Echo to screen to show progress.

   

     foreach ($row in $report) {     # Generate sum for this LUN

          if ($row.DATASTORE -eq $LUN.Name) {$VMSizeSum += $row.VMSIZE_MB}

     }

                                        # Create a blank row and add data to it.

     $DSRow = "" | select Datastore_Name,Capacity_MB,  FreeSpace_MB, Allocated_MB, Unallocated_MB

     $DSRow.Datastore_Name = $LUN.Name

     $DSRow.Capacity_MB = $LUN.CapacityMB

     $DSRow.FreeSpace_MB = $LUN.FreeSpaceMB

     $DSRow.Allocated_MB = [int]$VMSizeSum

     $DSRow.Unallocated_MB = $LUN.CapacityMB - [int]$VMSizeSum     # NB that if we have overallocated disk                                                  # space this will be a negative number

     $DSReport += $DSRow               # add the row to the structure.

}   

$DSReport | Export-Csv "C:\temp\Datastores.csv" -NoTypeInformation     # dump report to .csv

I get this error at line 14:

Get-View : 24/04/2014 9:54:14 AM    Get-View        Permission to perform this operation was denied. Required privilege 'System.Read' on managed object with id 'Datastore-datastore-14109'.

At C:\scripts\storage.ps1:23 char:33

+              $dsview = (Get-View <<<<  $disk.Datastore)                    # Datastore used by the disks

    + CategoryInfo          : NotSpecified: (:) [Get-View], NoPermission

    + FullyQualifiedErrorId : Client20_MoServiceImpl_GetNetInteropView_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

Get-View : 24/04/2014 9:54:14 AM    Get-View        View with Id  'Datastore-datastore-14109' was not found on the server(s).

At C:\scripts\storage.ps1:23 char:33

+              $dsview = (Get-View <<<<  $disk.Datastore)                    # Datastore used by the disks

    + CategoryInfo          : ObjectNotFound: (:) [Get-View], VimException

    + FullyQualifiedErrorId : Core_GetView_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

You cannot call a method on a null-valued expression.

At C:\scripts\storage.ps1:24 char:46


This worked perfectly prior to upgrading to vCenter 5.5

I am running the latest PowerCLI, and am logging in as administrator with full rights

Does anyone have any ideas?

Tags (3)
6 Replies
kunaludapi
Expert
Expert

Run below commands for some of the VMs (Replace VMname with your VM)

$VMinfo = Get-VM VMName | Get-View

$DatastoreID = $VMinfo.storage.perdatastoreUsage.datastore

$DatastoreInfo = Get-View $DatastoreID

$Datastore.name

Also run this. What datastore name do you see? (run Get-datastore and see if any datastore is not visible)

Get-Datastore -id Datastore-datastore-14109

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Reply
0 Kudos
LucD
Leadership
Leadership

It looks as if the account which you run the script is assigned a Role that is missing the basic "system.read" privilege.

Can you check ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
silverain
Contributor
Contributor

I'm running the script as the administrator. Both for Windowas & vCenter. It has all of the privelges assigned.

@kunaludapi

PowerCLI C:\scripts> $VMinfo = Get-VM 2035-DMZ

PowerCLI C:\scripts>

PowerCLI C:\scripts> $DatastoreID = $VMinfo.storage.perdatastoreUsage.datastore

PowerCLI C:\scripts>

PowerCLI C:\scripts> $DatastoreInfo = Get-View $DatastoreID

Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

At line:1 char:26

+ $DatastoreInfo = Get-View <<<<  $DatastoreID

    + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

"$VMinfo.storage.perdatastoreUsage.datastore" returns nothing.

Reply
0 Kudos
kunaludapi
Expert
Expert

You are missing

$VMinfo = Get-VM 2035-DMZ | get-view

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Reply
0 Kudos
LucD
Leadership
Leadership

That should be

$DatastoreID = $VMinfo.ExtensionData.storage.perdatastoreUsage[0].datastore

But note that the perDatastoreUsage property is an array, if your VM has files on more than 1 datastore, you will have to handle this in a ForEach loop.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

silverain
Contributor
Contributor

kunaludapi wrote:

You are missing

$VMinfo = Get-VM 2035-DMZ | get-view

No I didn't:

PowerCLI C:\scripts> $VMinfo.storage.perdatastoreUsage.datastore

PowerCLI C:\scripts> $VMinfo = Get-VM 2035-DMZ | get-view

PowerCLI C:\scripts> $VMinfo.storage.perdatastoreUsage.datastore

PowerCLI C:\scripts>

Reply
0 Kudos