Solved

windows powershell to remote servers

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 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

21 Experts available now in Live!

Get 1:1 Help Now