Jocker-H
Contributor
Contributor

PowerCli Script to collect logs from Multiples ESXI into the same Vcenter

Hello Team,

Im trying to create a script PowerCLI that collect logs  from specific ESXI servers into the same VCenter using this script but unfortunately it doesn't work and i dont know why !! Any suggestion please ?


$csvFilePath = "C:\esxi_info.csv"

$destinationFolder = "C:\Logs"

$esxiInfo = Import-Csv -Path $csvFilePath


foreach ($esxi in $esxiInfo) {
$esxiIP = $esxi.IP
$esxiUser = $esxi.User
$esxiPassword = $esxi.Password

# Connect to the ESXi server
Connect-VIServer -Server $esxiIP -User $esxiUser -Password $esxiPassword

# Generate the log bundle filename
$bundleFileName = "LogBundle_$($esxiIP.Replace('.', '_')).zip"
$bundleFilePath = Join-Path -Path $destinationFolder -ChildPath $bundleFileName

# Collect the log bundle
$task = Get-VMHost -Name $esxiIP | Get-Log -Bundle -DestinationPath $bundleFilePath -RunAsync

Write-Host "Collecting log bundle for ESXi host ($esxiIP)..."

# Wait for the log bundle collection task to complete
$task | Wait-Task

Write-Host "Log bundle collected for ESXi host ($esxiIP) and saved as $bundleFileName"

# Disconnect from the ESXi server
Disconnect-VIServer -Server $esxiIP -Confirm:$false
}

 

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership

Do you get errors?
Is the file created, or is it empty?


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

Reply
0 Kudos
Jocker-H
Contributor
Contributor

Hey Luck,

No there was no file created and no errors. 

what do you think about the script does it seems correct to  you ?

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership

The DestinationPath parameter on the Get-Log cmdlet wants a path, not a file.


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

Reply
0 Kudos
Jocker-H
Contributor
Contributor

Hi LuckD,

The "destinationPath" parameter already receive a path. Correct me if i'm wrong :

-DestinationPath $bundleFilePath

$destinationFolder = "C:\Logs" ==> indicate the path where the logs will be saved
$bundleFilePath = Join-Path -Path $destinationFolder -ChildPath $bundleFileName

Thanks in advance

 

Reply
0 Kudos
LucD
Leadership
Leadership

You attach the ZIP filename to that path (-DestinationPath $bundleFilePath).
That is a file, not a folder


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

Reply
0 Kudos
Jocker-H
Contributor
Contributor

Hi,

So the paramètres should be like this ?

$task = Get-VMHost -Name $esxiIP | Get-Log -Bundle -DestinationPath "C:\Logs" -RunAsync

Thanks

 

Reply
0 Kudos
LucD
Leadership
Leadership

Yes, and I would first run a test with 1 ESXi node without the RunAsync parameter.
Collecting a log bundle might take some time and you might hit the WebOperationsTimeout (default 300 seconds).
Increase the value with the Set-PowerCLIConfiguration cmdlet if needed.


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

Reply
0 Kudos