Windows Servers Uptime Report using PowerShell

M. Sheeraz Ansari 136 Reputation points
2022-12-14T14:36:19.267+00:00

Hi Folks,

A customer has mix of Windows servers (2012, 2016, 2019) on-premises environment. Customer needs to generate a report via PowerShell about the availability of servers. During my search I found a script on this link

and its modified version is attached.

270634-get-serveruptime.txt

Please note, this script reads windows events and based on that produces result. There is a problem where I need help, this script doesn't run against list of servers via a CSV file or a text file and we suspect it is not producing correct result.

Can somebody please review this script and help us with the right syntax or what is missing here?

Thanks in advance.

Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-12-14T15:43:17.213+00:00

    this script doesn't run against list of servers via a CSV file or a text file and we suspect it is not producing correct result.

    What error do you get? What output do you get and what is wrong with it? Did you follow the examples that are documented in the script?

        .EXAMPLE  
            PS C:\> Get-ADComputer -Filter "OperatingSystem -Like '*Windows Server*' -and Enabled -eq 'True'" | Export-Csv $env:USERPROFILE\desktop\serverlist.csv -NoTypeInformation  
            PS C:\> $CsvList = "$env:USERPROFILE\desktop\serverlist.csv"  
            PS C:\> $CsvList.Name | Get-ServerUptime -ShowProgress -Raw  
            Retrieving shutdown and startup events all systems in AD export to list (Progress of each server will display)...  
            WARNING: This could take several minutes!  
      
        .EXAMPLE  
            PS C:\> 'LAB-DC3','LAB-DC2','LAB-OFFCA','LAB-WAP','LAB-NDES' | Get-ServerUptime -Verbose | Format-Table  
            Retrieving shutdown and startup events all listed systems in verbose data and formatted as a table...  
            WARNING: This could take several minutes!  
      
    

  2. Rich Matheisen 47,901 Reputation points
    2022-12-14T16:27:37.94+00:00

    I think your problem is found on line #171 of the script. The comment says "# Remotely retrieve the events . . ." but the Invoke-Command runs only on the local machine because there's no "-ComputerName" or "-Session" parameter.

    There is a comment above that that says "# Create a new PSSession to be used throughout the script" but there's no code to create the session. Did you modify this section of the script???


  3. Rich Matheisen 47,901 Reputation points
    2022-12-14T19:06:28.337+00:00

    After correcting the two Invoke-Command cmdlets, run the script like this: .\ScriptName.ps1 -CsvList filepath to use a CSV file with the machine names in the "Name" column of the CSV file.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.