POWERSHELL - HOW TO FIND THE UPTIME OF SERVERS VIA POWERSHELL (IN DOMAIN)
We can get the uptime of multiple servers from powershell at the same time. In my example, I will be finding out the uptime of 2 servers which are part of a domain from a single computer.
Please follow the below steps to perform the same:-
1) I have created a text file name Servers.txt which has the name of all the 2 servers and as an example, I am keeping it in C drive which will be restarted.
2) Now I have created a variable $vmlist and will store the contents of the file Servers.txt which is kept on the location C:- Servers.txt. This needs to be done from power shell.
Note:- In my case, I am running from domain administrator account.
3) You can check the Content of the file Servers.txt by running the below command:-
Command:- echo $vmlist
4) Now to find out the uptime of the servers,type in the below command from one of the remote computers. In my example, I am doing it from the DC.
Get-WmiObject win32_operatingsystem -ComputerName $vmlist| select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
Output is:-

We can get the uptime of multiple servers from powershell at the same time. In my example, I will be finding out the uptime of 2 servers which are part of a domain from a single computer.
Please follow the below steps to perform the same:-
1) I have created a text file name Servers.txt which has the name of all the 2 servers and as an example, I am keeping it in C drive which will be restarted.
2) Now I have created a variable $vmlist and will store the contents of the file Servers.txt which is kept on the location C:- Servers.txt. This needs to be done from power shell.
Note:- In my case, I am running from domain administrator account.
3) You can check the Content of the file Servers.txt by running the below command:-
Command:- echo $vmlist
4) Now to find out the uptime of the servers,type in the below command from one of the remote computers. In my example, I am doing it from the DC.
Get-WmiObject win32_operatingsystem -ComputerName $vmlist| select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
Output is:-
No comments:
Post a Comment