Automation

 View Only
  • 1.  Getting the hostname

    Posted Mar 01, 2016 09:53 AM

    Hi

    I created this piece of Powershell to find out if some hosts report a datastore as inaccessible.

    $listdatastores = Get-Datastore

    ForEach( $DS in $listdatastores)

    {

        $DSView = Get-View $DS

        ForEach( $MountHost in $DSView.host )

        {

            if( -not $MountHost.MountInfo.Mounted )

                {

                    Write-Host $DS.Name $MountHost.Key $MountHost.MountInfo.Mounted $MountHost.MountInfo.Accessible

                }

            if( -not $MountHost.MountInfo.Accessible )

                {

                    Write-Host $DS.Name $MountHost.Key $MountHost.MountInfo.Mounted $MountHost.MountInfo.Accessible

                }

        }

    }

    The output is:

    UTRDS120-T1 HostSystem-host-388 True False

    UTRDS120-T1 HostSystem-host-267 True False

    UTRDS120-T1 HostSystem-host-51 True False

    UTRDS121-T1 HostSystem-host-388 True False

    UTRDS121-T1 HostSystem-host-51 True False

    Which is good, since it tells me that some datastores are inaccessible. But now it would be great to also report the name of the ESXi host, but I don't know how to go back from HostSystem-host-388 to a ESXi hostname.

    Gabrie



  • 2.  RE: Getting the hostname
    Best Answer

    Posted Mar 01, 2016 10:07 AM

    Try like this

    ForEach($DS in (Get-View -ViewType Datastore -Property Name,Host))

    {

        ForEach($MountHost in $DS.host )

        {

            if(-not $MountHost.MountInfo.Mounted )

            {

                Write-Host "$($DS.Name) $((Get-View -Id $MountHost.Key -Property Name).Name) $($MountHost.MountInfo.Mounted) $($MountHost.MountInfo.Accessible)"

            }

            if( -not $MountHost.MountInfo.Accessible )

            {

                Write-Host "$($DS.Name) $((Get-View -Id $MountHost.Key -Property Name).Name) $($MountHost.MountInfo.Mounted) $($MountHost.MountInfo.Accessible)"

            }

        }

    }



  • 3.  RE: Getting the hostname

    Posted Mar 01, 2016 10:28 AM

    Excellent, thank you!