VMware Cloud Community
Gabrie1
Commander
Commander
Jump to solution

Getting the hostname

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

http://www.GabesVirtualWorld.com
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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)"

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

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)"

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Gabrie1
Commander
Commander
Jump to solution

Excellent, thank you!

http://www.GabesVirtualWorld.com
0 Kudos