Hi All
is there a way to collect all tasks from vcenters?
the idea is to collects tasks and identify VMs that have issues
You could start with this.
But it will return all tasks. So you will have to filter further to get only the tasks that are for VMs.
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |
Where-Object{$_ -is [VMware.Vim.TaskEvent]}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD
I got the idea and just need your help as I need to collect all tasks from multiple vcenters so I create the first part but not sure how I can do for the rest
- Collect tasks from $vCenterIP [All parametre are needed]
- Create Excel File with worksheet based on vCenter name
---------------------------------------- Script --------------------------------------------
# LIST OF vCenter
$vCenterIP = "vcenter01","vcenter02","vcenter03","vcenter04","vcenter05","vcenter06"
# Connection to vCenter
foreach ($IPAddress in $vCenterIP){
Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443
}
#Connect to vcenter
$user = Read-Host "User"
$password = Read-Host "Password"
Write-Host -f green "Connecting to vCenter Server..."
Connect-VIServer -Server $vcenter -User $user -Password $password
$start = (Get-Date).AddDays(-5)
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) |
Where-Object{$_ -is [VMware.Vim.TaskEvent]}
You can use the Server parameter and loop through all connected vCenters.
Something like this
$vCenterIP = "vcenter01","vcenter02","vcenter03","vcenter04","vcenter05","vcenter06"
#Connect to vcenter
$user = Read-Host "User"
$password = Read-Host "Password"
# Connection to vCenters
foreach ($IPAddress in $vCenterIP){
Write-Host -f green "Connecting to vCenter Server..."
Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443
}
$start = (Get-Date).AddDays(-5)
$global:defaultVIServers | %{
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) -Server $_ |
Where-Object{$_ -is [VMware.Vim.TaskEvent]}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
to export all output in one excel file with worksheet can I use something like this
$fileName = ".\ALL_vCenter_Tasks_Report_" + (Get-Date -UFormat "%d-%b-%Y-%H-%M") + ".xlsx"
$reportvCenter01 = @()
$reportvCenter02= @()
$reportvCenter03= @()
$reportvCenter01 | Export-Excel -Path $fileName -WorksheetName 'vCenter01'
$reportvCenter02 | Export-Excel -Path $fileName -WorksheetName 'vCenter02'
$reportvCenter03 | Export-Excel -Path $fileName -WorksheetName 'vCenter03'
You could do like this
$vCenterIP = "vcenter01","vcenter02","vcenter03","vcenter04","vcenter05","vcenter06"
$fileName = ".\ALL_vCenter_Tasks_Report_" + (Get-Date -UFormat "%d-%b-%Y-%H-%M") + ".xlsx"
# Connection to vCenter
#Connect to vcenter
$user = Read-Host "User"
$password = Read-Host "Password"
foreach ($IPAddress in $vCenterIP){
Write-Host -f green "Connecting to vCenter Server..."
Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443
}
$start = (Get-Date).AddDays(-5)
foreach($vc in $global:defaultVIServers){
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) -Server $vc |
Where-Object{$_ -is [VMware.Vim.TaskEvent]} |
Export-Excel -Path $fileName -WorksheetName $vc.Name
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
the output is empty and only I can see task on PowerCLI window
Did you add the pipeline symbol (|) at the end of the Where-Object line?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thank you I missied it it's working fine now, but for some column I see this entry (VMware.Vim.DatacenterEventArgument) is that normal?
When a property in the event is an object on itself (in this case a DatacenterEventARgument), the Export-Excel cmdlet will display the object type and not the content.
In fact most properties in a TaskEvent are objects themselves.
You would probably get more information on the Task when you write the $event.Info property to the Excel file.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this for example
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) -Server $vc |
Where-Object{$_ -is [VMware.Vim.TaskEvent]} |
Select -ExpandProperty Info |
Export-Excel -Path $fileName -WorksheetName $vc.Name
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference