PowerShell 7.3 - guide with Retrieving Event Logs from Remote Machines Using WinRM
I'm sure I'm missing something obvious here, but I'm working on a project and hit a roadblock... I'm trying to retrieve event logs from multiple remote machines using PowerShell 7.3 and WinRM, but I'm working with an scenario where the script fails to connect to some machines intermittently. I've set up WinRM on the target machines and verified that the necessary firewall rules are in place. However, when I run the following script, I sometimes get the behavior: `New-PSSession : [RemoteMachineName] Connecting to remote server failed with the following behavior message: The WSMan service want to process the request.`. Here's the code I'm using: ```powershell $computers = @('Machine1', 'Machine2', 'Machine3') $sessionOptions = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck foreach ($computer in $computers) { try { $session = New-PSSession -ComputerName $computer -SessionOption $sessionOptions -ErrorAction Stop $logs = Invoke-Command -Session $session -ScriptBlock { Get-EventLog -LogName Application -Newest 5 } Remove-PSSession -Session $session $logs | Format-Table } catch { Write-Host "Failed to retrieve logs from $computer: $_" } } ``` I noticed that the failure seems to occur more frequently during periods of heavy load or when the remote machines are rebooting. I also checked the `WinRM` service status on the remote machines, and it appears to be running fine. Is there a way to make the connection attempt more resilient or to better handle these transient errors? Additionally, would it be beneficial to implement some sort of backoff strategy or logging for the errors that occur? Any suggestions would be greatly appreciated. For context: I'm using Powershell on Linux. Am I missing something obvious?