Updated March 15, 2023
Introduction to PowerShell Uptime
Uptime is a metric that denotes and it measures the successful operational duration of a computer network or hardware. IT industry terms the duration of the operational system as uptime. In PowerShell, the cmdlet gives the elapsed time of the recent boot of the operating system and this function is introduced in PowerShell 6.0. To fetch the uptime on Linux, Windows, and macOS, the user can go for Get – uptime cmdlet in PowerShell. The –since the command is used to fetch the recent time and date of the operating system is booted.
What is PowerShell Uptime?
PowerShell is used for configuration management and task automation using a command line function or scripting. PowerShell is executed on macOS, Linux, and Windows. Uptime command executes the information about how the system is running together successfully with the current time, number of running sessions, number of users and sessions, system average load for the past one minute, five minutes, and fifteen minutes.
How to Use PowerShell Uptime?
Hardware components like cables and switch keyboards are connected to form a server. It is off-site and works as intermediate transit and thus forms the crucial part of the operation. So the company’s infrastructure team consists of dedicated weekly or daily tasks to monitor the performance of the system via different metrics. Uptime is one of the mandatory metrics to measure the system performance, and it measures the amount of time that the system is ON without any shutdown or restart. The user doesn’t want the system to fail in the middle of the tough load and so he checks the uptime of the system. An Infrastructure team can fix the system and application health and manage it to prevent unexpected downtime. The diagnosis should be minimal so the user can fix the issue easily to ensure the company’s efficient working as time is money, and the business doesn’t want to face any unexpected shortage.
To ensure this Microsoft PowerShell is launched, keep an eye on uptime. A high uptime rate increases the system’s availability and reliability, whereas downtime is disturbing in terms of reputation and cost.
How to Check Server PowerShell Uptime?
As an efficient server admin, he should know what the system needs and when the system should be upgraded to meet the company’s standard operations. Periodically, the admin can advise the next action course to superiors and get downtime for restart.
Capacity management should be planned, and there should be considerable resources to manage the needs of the company. Based on the uptime, there should be a periodic check on machines whether it needs a restart or replacement. Hence uptime is a tedious measure in the business.
The user has to understand the terms of the common information model and windows management instrumentation. WMI is composed of multiple extensions and offers details about the operating system. Whereas the common information model provides management details like properties of the device and application. It also includes the business tools that enable IT to know about the infra and they can find it without any delay. The admin can access the common information model like uptime and other properties via WMI.
PowerShell Uptime Server 4 Ways
The PowerShell uptime can be found and fixed in four ways, and they are given below:
1. Windows Management Instrumentation Querying
The user can find the uptime of the windows server by WMI queries. The extension of WMI is used to calculate uptime in a class known as Wi32_operating system, and it is built with multiple properties. The Lastbootuptime command explains when the system has been rebooted recently. It also requires the CIM data, and it should be fixed.
Code:
Get –ciminstance – nameoftheclass _ win32_operatingsystem | select | lastbootuptime.
Output:
The output will be in the date and time format that is used to compute the uptime.
2. Windows Event Log
The admin can access this data in PowerShell via Get –win event command or get –eventlog command. It gives the details of event tracing logs and event logs placed on remote and local computers. Rather than viewing all the complete log files, the user can search the metrics and view them using individual ids. The code in PowerShell is used to get the last restart date and time.
Code:
Get –win event –providername _event log | where – object { $ - id.eq 1002 –or $ _.id –eq 1003} | select – object –first – timecreated
Output:
The important parameters in Get-winevent are:
- computername: Gives the name of the computer where the system log is stored.
- Credential: User account which has the permission to perform this action.
- Filterhashtable: Takes the queries in hashtable format.
- filterXML: Gives the structured XML query.
- force: Gives the debug log if the name of the computer has wildcard characters.
3. Using the Get-uptime Command
The admin can use Get-uptime to fetch elapsed time of the last reboot.
Code:
Get –uptime and [-since]
Output:
4. Custom Scripts
The user can develop their scripts in groups develop. The command below gives the script executed by a computer and parses the event log in the computer to find the last restart time. Then it computes the total time the server is running. It also gives the history of the computer’s start and stops time.
Code:
-/ get –serveruptimereport .ps1 –the name of the computer comp 1
Output:
The advantage of this method is the user can find the uptime of multiple windows servers with similar commands since the script works in an array. The script can also be customized to meet the desired requirements.
Conclusion
Hence PowerShell helps the business to give uninterrupted services to the users. Classifying the cause of downtime can help in capacity planning, budgeting, better infrastructure management, and decision making.
Recommended Articles
This is a guide to PowerShell Uptime. Here we discuss the introduction, and how to check server PowerShell uptime? And server 4 ways. You can also go through our other related articles to learn more –