VMware Cloud Community
DDinu
Enthusiast
Enthusiast

How to get Task and Events on Datastore, Through Powercli ?

I was trying the below, but it trowed and error.

$datas = Get-Cluster -Name "xxxx" | Get-Datastore

foreach($ds in $datas){

    $dview = $ds | Get-View

    Get-VIEvent -Entity $dview |  ? {$_.FullFormattedMessage -match "Lost Access"}

}

Get-VIEvent : 10/17/2016 10:25:04 AM    Get-VIEvent        Events can be retrieved only for inventory objects. The entity of type 'VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl' will be ignored.   

At line:1 char:1

+ Get-VIEvent -Entity $ds

+ ~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Get-VIEvent], InvalidArgument

    + FullyQualifiedErrorId : Core_GetEvent_DoWork_InvalidEntityType,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetEvent

0 Kudos
2 Replies
estokes_vmware
VMware Employee
VMware Employee

That looks like a bug based on what I see as well.  As a workaround you should be able replace your Get-VIEvent line with the following to search for the events (not ideal but should work):

Get-VIEvent | where {( ($_.entity.entity -eq $ds.ExtensionData.MoRef) -and ($_.FullFormattedMessage -match "Lost Access") )}

0 Kudos
DDinu
Enthusiast
Enthusiast

unfortunately it not getting an output. Not sure why, Checking on it. As a temporary work around have got the below one.

This is not a best method. But it is working.

Start-Transcript -path "C:\temp\storageioupgradecheck.txt"

If ($global:DefaultVIServers) {

    Disconnect-VIServer -server * -Force -Confirm:$false

    }

$track =@()

$report = @()

$vc = Read-Host "Enter the vcenter name"

$vcconnect = Connect-VIServer -Server $vc

$answer = ""

while ($answer -notmatch "[y|n]"){

    $answer = read-host "Would you like to check ALL ESXI in vCenter? (Y/N)"

}

switch($answer){

   

    "Y" { $inp = $vcconnect

           try{

          $esxi = Get-VMHost -Server $inp

          }Catch{

            Write-Host "Unable to get esxi details due to $_"

            break

          }

      }

    "N" { $inp = Read-Host "Enter the name of the cluster"

           try{

             $esxi = Get-Cluster -Name $inp | Get-VMHost

           }Catch{

             Write-Host "Unable to get esxi details due to $_"

             break

          }

       }

    }

$startdate = Read-Host "Enter the Start date from where you would like to see the events format : mm/dd/yyyy)"

$Details = @()

$i = 1

$y = 1

foreach($esx in $esxi){

    Write-Host "$esx"

    $Y

     $track = $esx | Get-VIEvent -Start $startdate | ? {$_.FullFormattedMessage -match "Lost Access"}

        foreach($ent in ($track)){

        Write-Host "in loop $i"

            $Details = "" | Select-Object Host, Message, Time

            $Details.host = $ent.host.name

            $Details.Message = $ent.FullFormattedMessage

            $Details.Time = $ent.CreatedTime

            $report += $Details

            $i++

           

}

$y++

}

$report | export-csv -Path C:\temp\storageupgradecheck.csv -NoTypeInformation

Disconnect-VIServer -Server * -Force -Confirm:$false

Stop-Transcript

0 Kudos