Solved

windows powershell to remote servers

Posted on 2013-06-28
5
328 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 69

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 69

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article will help you understand what HashTables are and how to use them in PowerShell.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

773 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