Solved

windows powershell to remote servers

Posted on 2013-06-28
5
325 Views
Last Modified: 2013-09-06
I have one desktop PC running windows 7 + powershell.

I have a mixture of windows 2003 and 2008 servers.

I would like to write a script which logs into each one and report back the uptime of each and then export to csv file.

My question is if it is mandatory to have powershell installed on the windows 2003 or windows 2008 servers? What technology will be used by my windows 7 machine to communicate with the servers?
0
Comment
Question by:Ikky786
5 Comments
 
LVL 19

Expert Comment

by:Patricksr1972
ID: 39283911
Hi,

Powershell is a nice util for this, yes it is mandatory to have it installed on your servers.
This is what the scripting guys say about server uptime.
0
 
LVL 12

Accepted Solution

by:
SreRaj earned 500 total points
ID: 39283922
Hi,

Please try the following script. It takes input from a text file, ServerList.txt. This file should contain a server name in each line. Output will be stored in a csv file UpTimeReport.csv.

$ServerList = Get-Content ServerList.txt
$DataOutput = $Null
Set-Content UpTimeReport.csv $Null
$Header = "Server Name,Uptime"
Out-File UpTimeReport.csv -InputObject $Header -Encoding ASCII -Force
ForEach($Server in $ServerList){
    If(Test-Connection -ComputerName $Server -Count 4 -ErrorAction SilentlyContinue){
        $WMIServer = gwmi Win32_OperatingSystem -ComputerName $Server
        $LastBootTime = $WMIServer.ConvertToDateTime($WMIServer.LastBootUpTime)  
        [TimeSpan]$UpTime = New-TimeSpan $LastBootTime $(Get-Date)
        $DataOutput = '"'+$Server+'","'+"$($UpTime.Days) Days, $($UpTime.Hours) Hours and $($UpTime.Minutes) Minutes"+'"'
        Out-File UpTimeReport.csv -InputObject $DataOutput -Append -Encoding ASCII -Force
        $DataOutput
    }
    else{
        $DataOutput = '"'+$Server+'","Server not reachable"'
        Out-File UpTimeReport.csv -InputObject $DataOutput -Append -Encoding ASCII -Force
    }
}

Open in new window

0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39284661
As you can see from the script, it is NOT mandatory to have PowerShell installed on the servers. But it is advisable.
Some cmdlets have remoting capabilities different from PowerShell - WMI is one example. It only requires to have the WMI services running on the target, which they do by default.

Only if you want to remote control, execute complex scripts remotely and the like you will have to have PS installed.
0
 

Author Comment

by:Ikky786
ID: 39286974
Of course it doesn't have to be wmi , I wasn't aware powershell had its own cmdlets to download and scan windows updates
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39287269
PS hasn't them build in, but one of the great features is that you can load modules at your need to extend capabilities ....
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now