Automation

 View Only
Expand all | Collapse all

Fetch detail of rebooted servers after host Abruptly down

  • 1.  Fetch detail of rebooted servers after host Abruptly down

    Posted May 05, 2023 07:37 PM

    Hello  ,

    Request your help... after migrating windows based vCenter to appliance below HA trigger reboot report script stopped working.

     

    Get-VIEvent -MaxSamples 100 -Start (Get-Date).AddDays(-1) -Type Warning | Where {$_.FullFormattedMessage -match "restarted"} |select CreatedTime,FullFormattedMessage | sort CreatedTime -Descending

     

    Error

     

    PS C:\WINDOWS\system32> Get-VIEvent -MaxSamples 100 -Start (Get-Date).AddDays(-1) -Type Warning | Where {$_.FullFormattedMessage -match "restarted"} |select CreatedTime,FullFormattedMessage | sort CreatedTime -Descending


    Get-VIEvent : 5/5/2023 3:35:47 PM Get-VIEvent The request channel timed out while waiting for a reply after 00:05:00. Increase the timeout
    value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a
    portion of a longer timeout.
    At line:1 char:1
    + Get-VIEvent -MaxSamples 100 -Start (Get-Date).AddDays(-1) -Type Warni ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Get-VIEvent], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetEvent



  • 2.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 05, 2023 07:53 PM

    Try using Set-PowerCLIConfiguration to set the timeout to a higher value, or disable the timeout.

    # Default timeout is 300 seconds, change to 600
    Set-PowerCLIConfiguration -WebOperationTimeoutSeconds 600
    
    # Disable timeout
    Set-PowerCLIConfiguration -WebOperationTimeoutSeconds -1

     



  • 3.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 05, 2023 08:08 PM
      |   view attached

     ,, Still getting same error after disable.



  • 4.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 05, 2023 08:55 PM

    It is still at 300 seconds, it didn't change.

    You have to specify all Scopes, and then stop/start your session



  • 5.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 06, 2023 12:09 PM
      |   view attached

     , Could you please check if I am missing anything. Screenshot enclosed.



  • 6.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 06, 2023 12:15 PM

    Did you still get the timeout?



  • 7.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 07, 2023 07:18 AM

     This time there is no timeout issue, but script doesn't end and stuck for indefinifinte time of periord without any output or fail.



  • 8.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 07, 2023 10:46 AM

    Which PowerCLI version are you using?

    As an alternative, you might want to try my Get-VIEventPlus function.

     

    function Get-VIEventPlus {
    	<#   
    	.SYNOPSIS  Returns vSphere events    
    	.DESCRIPTION The function will return vSphere events. With
    		the available parameters, the execution time can be
    	   improved, compered to the original Get-VIEvent cmdlet. 
    	.NOTES  Author:  Luc Dekens   
    	.PARAMETER Entity
    	   When specified the function returns events for the
    	   specific vSphere entity. By default events for all
    	   vSphere entities are returned. 
    	.PARAMETER EventType
    	   This parameter limits the returned events to those
    	   specified on this parameter. 
    	.PARAMETER Start
    	   The start date of the events to retrieve 
    	.PARAMETER Finish
    	   The end date of the events to retrieve. 
    	.PARAMETER Recurse
    	   A switch indicating if the events for the children of
    	   the Entity will also be returned 
    	.PARAMETER User
    	   The list of usernames for which events will be returned 
    	.PARAMETER System
    	   A switch that allows the selection of all system events. 
    	.PARAMETER ScheduledTask
    	   The name of a scheduled task for which the events
    	   will be returned 
    	.PARAMETER FullMessage
    	   A switch indicating if the full message shall be compiled.
    	   This switch can improve the execution speed if the full
    	   message is not needed.   
    	.EXAMPLE
    	   PS> Get-VIEventPlus -Entity $vm
    	.EXAMPLE
    	   PS> Get-VIEventPlus -Entity $cluster -Recurse:$true
    	#>
    	 
    	  param(
    		[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$Entity,
    		[string[]]$EventType,
    		[DateTime]$Start,
    		[DateTime]$Finish = (Get-Date),
    		[switch]$Recurse,
    		[string[]]$User,
    		[Switch]$System,
    		[string]$ScheduledTask,
    		[switch]$FullMessage = $false
    	  )
    	 
    	  process {
    		$eventnumber = 100
    		$events = @()
    		$eventMgr = Get-View EventManager
    		$eventFilter = New-Object VMware.Vim.EventFilterSpec
    		$eventFilter.disableFullMessage = ! $FullMessage
    		$eventFilter.entity = New-Object VMware.Vim.EventFilterSpecByEntity
    		$eventFilter.entity.recursion = &{if($Recurse){"all"}else{"self"}}
    		$eventFilter.eventTypeId = $EventType
    		if($Start -or $Finish){
    		  $eventFilter.time = New-Object VMware.Vim.EventFilterSpecByTime
    		if($Start){
    			$eventFilter.time.beginTime = $Start
    		}
    		if($Finish){
    			$eventFilter.time.endTime = $Finish
    		}
    		}
    	  if($User -or $System){
    		$eventFilter.UserName = New-Object VMware.Vim.EventFilterSpecByUsername
    		if($User){
    		  $eventFilter.UserName.userList = $User
    		}
    		if($System){
    		  $eventFilter.UserName.systemUser = $System
    		}
    	  }
    	  if($ScheduledTask){
    		$si = Get-View ServiceInstance
    		$schTskMgr = Get-View $si.Content.ScheduledTaskManager
    		$eventFilter.ScheduledTask = Get-View $schTskMgr.ScheduledTask |
    		  where {$_.Info.Name -match $ScheduledTask} |
    		  Select -First 1 |
    		  Select -ExpandProperty MoRef
    	  }
    	  if(!$Entity){
    		$Entity = @(Get-Folder -Name Datacenters)
    	  }
    	  $entity | %{
    		  $eventFilter.entity.entity = $_.ExtensionData.MoRef
    		  $eventCollector = Get-View ($eventMgr.CreateCollectorForEvents($eventFilter))
    		  $eventsBuffer = $eventCollector.ReadNextEvents($eventnumber)
    		  while($eventsBuffer){
    			$events += $eventsBuffer
    			$eventsBuffer = $eventCollector.ReadNextEvents($eventnumber)
    		  }
    		  $eventCollector.DestroyCollector()
    		}
    		$events
    	  }
    	}
    	 
    Get-VIEventPlus -MaxSamples 100 -Start (Get-Date).AddDays(-1)


  • 9.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 08, 2023 05:43 PM

    Thanks  for sharing the script. I run your script in lab but this script keeping running for a long time & extracting data in bulk that is probably not relevant to me. 

     

    Below is the powershell version.

     

    PS C:\temp> $PSVersionTable

    Name Value
    ---- -----
    PSVersion 5.1.17763.3770
    PSEdition Desktop
    PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
    BuildVersion 10.0.17763.3770
    CLRVersion 4.0.30319.42000
    WSManStackVersion 3.0
    PSRemotingProtocolVersion 2.3
    SerializationVersion 1.1.0.1



  • 10.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 08, 2023 06:13 PM

    Which Event are you actually looking for?
    A Guest OS reboot produces a VMware.Vim.VmGuestRebootEvent.
    I'm not sure which FullFormattedMessage would contain 'restarted'.

    The reason I provided my Get-VIEventPlus function is that you can use the EventType parameter.
    That way the function will only return events for that specific type.
    The Get-VIEvent cmdlet does in fact only support bulk retrieval, it is in the Where-clause afterward that you filter out the events you actually want.



  • 11.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 08, 2023 06:30 PM

    Thank you  for detailed information.

    I just need details about those servers which was restarted by HA in case of host failure.



  • 12.  RE: Fetch detail of rebooted servers after host Abruptly down

    Posted May 08, 2023 06:36 PM

    Then you need the EventEx event with the TypeId com.vmware.vc.ha.VmRestartedByHAEvent

    Get-VIEventPlus -EventType 'com.vmware.vc.ha.VmRestartedByHAEvent' -Start (Get-Date).AddDays(-1)