Hi Guys
I have a customer that has problems with Outlook freezing. I thought that this was caused that the Exchange server stopped responding. Then i thought that i might make a small script that pings destinations and writes the output to CSV file. The script are not working as expected as there is some kind of buffer under-run. Any thoughts on how to optimize the script, or if it's even possible would be greatly appreciated :)
[CmdLetBinding()] Param( $HostNames = "dr.dk" ) BEGIN{ $output = @() $data = @() $objects = @() [int]$counter = 0 foreach ($hostname in $HostNames) { $objects += New-Object -TypeName PSObject -Property @{"Hostname"=$hostname;"IP"=([Net.DNS]::GetHostEntry($hostname).AddressList.IpAddressToString) }} } PROCESS{ Write-Host "Press q Key to stop testing" while ($true) { if ($Host.UI.RawUI.KeyAvailable -and ("q" -eq $Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").Character)) { Write-Host "Stopping..." break } Write-Verbose "Defining Props" $props = @{ "Source"=($env:COMPUTERNAME); "Date" = Get-Date -Format d "Time" = Get-Date -Format T } Write-Verbose "Defining Object" $out = New-Object -TypeName psobject -Property $props foreach ($object in $objects) { $test = try {Test-Connection $object.ip -Count 1 -ErrorAction Stop| select -ExpandProperty ResponseTime } catch { Write-Output "FAILED"} Add-Member -InputObject $out -Name $object.HostName -Value $test -MemberType NoteProperty } $data += $out $counter++ Start-Sleep -Seconds 1 if ($counter -eq 60) { if (Test-Path "C:\script\PingLog.csv") { $dataold = Import-Csv "C:\script\PingLog.csv" -Delimiter ";" $output += $dataold $output += $data $output | Export-Csv -Path "C:\script\PingLog.csv" -Encoding "UTF8" -Delimiter ";" -NoTypeInformation } else { $data | Export-Csv -Path "C:\script\PingLog.csv" -Encoding "UTF8" -Delimiter ";" -NoTypeInformation } $counter = 0 } } } END{ if (Test-Path "C:\script\PingLog.csv") { $dataold = Import-Csv "C:\script\PingLog.csv" -Delimiter ";" $output += $dataold $output += $data $output | Export-Csv -Path "C:\script\PingLog.csv" -Encoding "UTF8" -Delimiter ";" -NoTypeInformation } else { $data | Export-Csv -Path "C:\script\PingLog.csv" -Encoding "UTF8" -Delimiter ";" -NoTypeInformation } }