Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #setup vi api
  2. if ((Get-PSSnapin "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null) {
  3.     Add-PSSnapin "VMware.VimAutomation.Core"
  4. }
  5.  
  6. #connect to vcenter
  7. Connect-VIServer vcenter
  8.  
  9. $results = @()
  10. $vmhosts = Get-VMHost
  11. foreach ($vmhost in $vmhosts) {
  12.     Write-Host "Checking $vmhost"
  13.     $datastores = Get-Datastore -VMHost $vmhost | Where-Object {$_.Type -eq 'NFS'}
  14.     foreach ($datastore in $datastores) {
  15.         if(!$datastore.Accessible){
  16.             $nfshost = $datastore.ExtensionData.Info.NAS.RemoteHost
  17.             $nfspath = $datastore.ExtensionData.Info.NAS.RemotePath
  18.             $nfsname = $datastore.Name
  19.             Write-Host "$nfsname on $vmhost is not accessable, removing and re-adding as $nfshost : $nfspath."
  20.             Remove-Datastore -VMHost $vmhost -Datastore $nfsname -Confirm:$false
  21.             New-Datastore -Nfs -VMHost $vmhost -Name $nfsname -Path $nfspath -NfsHost $nfshost
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement