Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 230777

Script error (Works on vCenter 4.x, errors on 5.x)

$
0
0

Hi Everyone,

 

LucD kindly provided me a script to produce a report on think provisioned virtual disks in my infrastructure. I used it extensively on multiple 4.x vCenter servers and it worked perfectly.

 

I've recently upgraded to vSphere 5, and re-ran the script but encountering issues. The script itself hasn't been modified, so I'm lead to believe that something has changed between these version numbers that's affecting the script behavior.

 

Here is the script:

 

$report = @()
$allvms = Get-VM
$allvms += Get-Template             
foreach ($vm in $allvms) {  $vmview = $vm | Get-View    $diskTab = @{}  $vmview.LayoutEx.Disk | %{    $filekeys = @()    $_.Chain | %{      $fileKeys += $_.FileKey       }    $size = $vmview.LayoutEx.File | where {$filekeys -contains $_.Key} |       Measure-Object -Property Size -Sum | Select -ExpandProperty Sum     $diskTab.Add($_.Key,$size)  }    foreach($dev in $vmview.Config.Hardware.Device){    if($dev.Backing.ThinProvisioned -eq $true) {        $row = "" | select VMNAME, HD, DATASTORE, VMSIZE_GB, VMUSED_GB, PERCENT          $row.VMNAME = $vmview.Config.Name          $row.HD = $dev.DeviceInfo.Label          $row.DATASTORE = $dev.Backing.FileName.Split(']')[0].Split('[')[1]        $row.VMSIZE_GB = [math]::Round(($dev.CapacityInKB/1MB),2)        $row.VMUSED_GB = [math]::Round(($diskTab[$dev.Key]/1GB),2)        $row.PERCENT = [math]::Round(($row.VMUSED_GB/$row.VMSIZE_GB*100),2)        $report += $row    }  }
}
$report | Export-Csv "C:\Test.csv" -NoTypeInformation -UseCulture 

 

And the errors: (I perform a connect-viserver prior to running the script). In both cases a report is produced

 

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 U:\Useful Scrips\VMware PowerCLI\ThinProvisionedVM's.ps1:6 char:27

+   $vmview = $vm | Get-View <<<<

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

   idationException

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

 

 

 

Exception calling "Add" with "2" argument(s): "Key cannot be null.

Parameter name: key"

At U:\Useful Scrips\VMware PowerCLI\ThinProvisionedVM's.ps1:15 char:14

+     $diskTab.Add <<<< ($_.Key,$size)

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

 

Does anyone know what changes from 4.x to 5.x could result in the above behavior?

 

Thanks,


David


Viewing all articles
Browse latest Browse all 230777

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>