Last active
June 23, 2016 09:44
-
-
Save vMarkusK/9d502748722d2e14c77a84f129c5c775 to your computer and use it in GitHub Desktop.
Check All VMFS Datastores connected on all VMware ESXi Hosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start Load VMware Snapin (if not already loaded) | |
if (!(Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) { | |
if (!(Add-PSSnapin -PassThru VMware.VimAutomation.Core)) { | |
# Error out if loading fails | |
Write-Error "ERROR: Cannot load the VMware Snapin. Is the PowerCLI installed?" | |
Exit | |
} | |
} | |
# End Load VMware Snapin (if not already loaded) | |
# Start Global Definitions | |
$VIServer = "yourvCenter.lan.local" | |
$DataCenterName = "yourDataCenter" | |
# End Global Definitions | |
# Start vCenter Connection | |
Write-Output "Starting to Process vCenter Connection to " $VIServer " ..." | |
$OpenConnection = $global:DefaultVIServers | where { $_.Name -eq $VIServer } | |
if($OpenConnection.IsConnected) { | |
Write-Output "vCenter is Already Connected..." | |
$VIConnection = $OpenConnection | |
} else { | |
Write-Output "Connecting vCenter..." | |
$VIConnection = Connect-VIServer -Server $VIServer | |
} | |
if (-not $VIConnection.IsConnected) { | |
Write-Error "Error: vCenter Connection Failed" | |
Exit | |
} | |
# End vCenter Connection | |
# Start Check All Datastores on all Hosts | |
$MyErrors = "" | |
$myDataCenter = Get-Datacenter -Name $DataCenterName | |
$AllStores = $myDataCenter | Get-Datastore | where {$_.Accessible -eq "True"} | Sort Name | |
$AllHosts = $myDataCenter | Get-VMhost | where {$_.ConnectionState -eq "Connected"} | Sort Name | |
foreach ($myHost in $AllHosts) { | |
foreach ($myStore in $AllStores) { | |
try { | |
Write-Output "Check $myStore on $myHost" | |
$DS = $myHost | Get-Datastore -Name $($myStore.Name) -ErrorAction Stop | |
} | |
catch { | |
Write-Output " ...Not Found" | |
$MyErrors += "Datastore $myStore not found on $myHost `n" | |
} | |
} | |
} | |
# End Check All Datastores on all Hosts | |
Write-Output "" $MyErrors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment