PowerShell output log showing incorrect information

I’m currently modifying a script written by a previous employee, and the main purpose of the script is to restart some servers. Currently, the portion of the script that actually goes through the restarts looks like this:

`
#For privacy reasons, the actual file path is replaced with “File Path”
Clear-Host
$YN = Read-Host -Prompt “CONFIRM REBOOT [Y/N]”

   if(($YN -eq "Y") -or ($YN -eq "y"))
   {
       Get-ChildItem -Path "\File PathServer RestartsLogsRestart Logs" -Recurse -File | Move-Item -Destination "\File PathServer RestartsLogsRestart LogsArchive" -Force

       $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
       $Log = New-Item "\File PathServer RestartsLogsRestart Logs$(Get-Date -f yyyy-MM-dd_hh-mm-ss) Restarts.txt" -ItemType File -Force
       $Date = Get-Date -Format "dd-MMM-yyyy hh:mm:ss"
       $Now = [datetime]::Now

       Clear-Host
       Write-Host `n `n `n
       Write-Host "Rebooting all servers and verifying reboot status..." `n `n
       Write-Host "Please standby, process may take up to 30 minutes..." `n `n

       #Below, $Servers is declared elsewhere, pointing to a .txt file with a list of server names
       Restart-Computer -ComputerName $Servers -Wait -For PowerShell -Delay 2 -Force -Timeout 1800

       "----------------------------------Script executed on $Date----------------------------------" + "`r`n" | Out-File $Log -Append

       foreach($Server in $Servers)
       {
           $LastBoot = (Get-CimInstance Win32_OperatingSystem -ComputerName $Server -EA 0).LastBootUpTime
           $PingRequest = Test-Connection -ComputerName $Server -Count 1 -Quiet

           if(($PingRequest -eq $true) -and ($LastBoot -gt $Now))
           {
               Add-Content -Path $Log -Value "$Server`: Reboot Successful."
           }
           elseif ($PingRequest -eq $false)
           {
               Add-Content -Path $Log -Value "$Server`: Server not detected, please confirm"
           }
           else
           {
               Add-Content -Path $Log -Value "$Server`: Restart not detected, please restart server manually"
           }
       }

       Clear-Host
       Write-Host `n `n `n
       Write-Host "All done!" `n
       Write-Host "Please review logs, as script may have run into problems." `n `n
       Log-Location
       Pause
   }
   else
   {
       Clear-Host
       Write-Host `n `n `n
       Write-Host "Server Reboots Aborted." `n `n
       Pause
   }

`

Currently, upon confirmation from user, it will take the log from the previous restarts and move that into an archive folder. After moving the previous log, it will create a new log in it’s place, and figure out the current time ($Now). After that, it restarts the servers, then pings them, comparing last boot up time to $Now, and puts the results in the log.

When recently running the script, I kept pinging the first server on the list with command prompt to see if it was working in real time. As the script ran, I was able to ping it, then I wasn’t able to ping it for a moment, then I was able to ping it again, so I know that at least first server restarted. However, when I checked the log after the script timed-out, not only did it display only 5 servers out of 13 total, it said “Restart not detected, please restart server manually” for all five it logged, including the one I tracked.
Based on my understanding, the script should be restarting all the servers (which it appears to be doing) and once it’s done doing that, compare the boot time to $Now (which boot time should be greater than $Now) and ping each server. The things I’m not understanding are as follows:

  1. Why didn’t the first server get logged as “Reboot Successful” when I know for certain the server was restarted?

  2. Why is the output log only displaying 5 of the 13 servers and not all 13?

    Is there something obvious I’m missing here, or do I need to heavily rework this portion of the script?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật