CTX.AL.EnumerateVsphereDisks.ps1
<#PSScriptInfo
.VERSION 1.5.1 .GUID 669f956a-0720-457a-b5b2-e39b5f3ed932 .AUTHOR Citrix Image Portability Engineering .COMPANYNAME Citrix .COPYRIGHT (c) Citrix. All rights reserved. .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA #> <# .DESCRIPTION Enumerate disks on a vSphere server. #> param( [string]$ConfigJsonFile, [string]$DiskFileName, [string]$VsphereDomain, [string]$VsphereUser, [string]$VspherePassword, [switch]$IgnoreCert, [switch]$Clean ) Function Enumerate-VSphereDisks([psobject]$config) { $vsphereHost = $config.Get("VsphereHost") $smbUserAndDomain = "$VsphereDomain\$VsphereUser" $err = "" LogIt "--- Connecting to vSphere host $vsphereHost as $smbUserAndDomain" $server = Connect-VIServer -Server $vsphereHost -Protocol https -User $smbUserAndDomain -Password $VspherePassword -ErrorVariable "err" -ErrorAction SilentlyContinue if (!$server) { LogIt "--- Failed to connect to vSphere $vsphereHost as $smbUserAndDomain error: $err" exit -1 } $vsphereDataStore = $config.Get("VsphereDataStore") if ($vsphereDataStore) { $datastores = Get-Datastore -Name $vsphereDataStore } else { $datastores = Get-Datastore } foreach ($datastore in $datastores) { $dUrl = $datastore.ExtensionData.info.url Write-Host "$($datastore.Name): $dUrl" $disks = Get-HardDisk -Datastore $datastore.Name foreach ($disk in $disks) { if ($disk.Name -eq $DiskFileName) { $diskPath = (-Split $disk.Filename)[1] $uiPath = "[$($datastore.Name)] $diskPath" $diskUrl = "$dUrl$diskPath" Write-Host " Disk path $uiPath has URL $diskUrl Type $($disk.DiskType) Size $($disk.CapacityGB)GB" } } } } LogInit "EnumerateDisks.log" $Clean LogIt "*** Enumerating Disks ***" $config = New-Configuration $config.Load($ConfigJsonFile) if ($IgnoreCert) { LogIt "--- Ignoring vSphere host cert" Add-Type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy } Enumerate-VSphereDisks $config |