Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #setup vi api
- if ((Get-PSSnapin "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null) {
- Add-PSSnapin "VMware.VimAutomation.Core"
- }
- #connect to vcenter
- Connect-VIServer vcenter
- $results = @()
- $vmhosts = Get-VMHost
- foreach ($vmhost in $vmhosts) {
- Write-Host "Checking $vmhost"
- $datastores = Get-Datastore -VMHost $vmhost | Where-Object {$_.Type -eq 'NFS'}
- foreach ($datastore in $datastores) {
- if(!$datastore.Accessible){
- $nfshost = $datastore.ExtensionData.Info.NAS.RemoteHost
- $nfspath = $datastore.ExtensionData.Info.NAS.RemotePath
- $nfsname = $datastore.Name
- Write-Host "$nfsname on $vmhost is not accessable, removing and re-adding as $nfshost : $nfspath."
- Remove-Datastore -VMHost $vmhost -Datastore $nfsname -Confirm:$false
- New-Datastore -Nfs -VMHost $vmhost -Name $nfsname -Path $nfspath -NfsHost $nfshost
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement