Link to home
Start Free TrialLog in
Avatar of SAM IT
SAM IT

asked on

This script has to run not aganist multiple servers using csv

This comment is working only if i add computer name after -computername.

IF I add csv path for multiple servers its not working

_________________________________________________________________________________
Invoke-Command -scriptblock { iisreset /status } -computername C:\Users\test\users.csv
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

It will not read a CSV file for you, you have to do that first.

If the CSV file had a column named ComputerName, which contained the list, you could use:
Invoke-Command -scriptblock { iisreset /status } -computername (Import-Csv C:\Users\test\users.csv).ComputerName

Open in new window

If the CSV file is just a raw list of computers (no headers, no other columns) you could use Get-Content instead.
Invoke-Command -scriptblock { iisreset /status } -computername (Get-Content C:\Users\test\users.csv)

Open in new window

Whatever happens you have to handle reading the CSV file first, then pass it into the ComputerName parameter which is expecting an array of strings (String[]).
Avatar of SAM IT
SAM IT

ASKER

Thanks for response

Getting out put with out server name for service status.

I tried to add | format-table computer, status , no luck

please find the out put screen shot
iis.jpg
Looking better. The trouble you have now is that the command you're running doesn't return an object, there's nothing for it to add the computer name to.

Even then, there's no Status field by default. This example will give you a ComputerName property because an object is being returned. But it won't give status, you'd have to define status (make up code that creates it, and gives it a value).
Invoke-Command { Get-Process -id $PID | Select Name } -ComputerName SomeComputer

Open in new window

Let's just see if those values returned by iisreset are strings:
Invoke-Command -scriptblock { New-Object PSObject -Property @{Status=(iisreset /status)} } -computername (Get-Content C:\Users\test\users.csv)

Open in new window

Avatar of SAM IT

ASKER

Getting below output error

PS C:\Windows\system32> Invoke-Command -scriptblock { New-Object PSObject -Property @{Status=(iisreset /status)} } -computername (Get-Content C:\Users\Narasimha.s\Desktop\iistest.csv)
[Computername] Connecting to remote server Computername failed with the following error message : WinRM cannot process the request. The following 
error occurred while using Kerberos authentication: Cannot find the computer Computername. Verify that the computer exists on the network and that 
the name provided is spelled correctly. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (Computername:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionStateBroken

Status                                             PSComputerName                                    RunspaceId                                       
------                                             --------------                                    ----------                                       
{, Status for Windows Process Activation Servic... ep-ts-wss-01                                      7a544dc1-77a0-46ca-be87-b706941c9127             
{, Status for IIS Admin Service ( IISADMIN ) : ... AP-TS-wss-01 

Open in new window

Avatar of SAM IT

ASKER

please find the attached scree shot , for similar command getting out put with computername
test.jpg
I can't help you much with that one. The error message says one of the computers you're trying to poll doesn't exist, that's not a code problem :)
Avatar of SAM IT

ASKER

Now I am getting out. perfectly

But there 03 service are running for IIS out put is mentioned in one excel line in landscape format , Cant we make it has a row wise and out put starts from PS computername status
output.jpg
Avatar of SAM IT

ASKER

using format table now iam getting out in this format pscomputername status, how to get the output of services in coloum wise format
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAM IT

ASKER

Sir, you are excellent really . In very short time you have written the script.

Thank you so much . If you are at twitter I will become a fan of you

Thanks for support.
Avatar of SAM IT

ASKER

Best solution
Avatar of SAM IT

ASKER

can we run this script against windows servers 2003 servers? if not can we use the same script in to .bat file ?
You can run it against 2003 if the 2003 servers have Windows Remoting configured (remoting was introduced with PowerShell 2.0, but it isn't enabled by default).

Ideally the 2003 boxes should have at least PowerShell 3 installed, the script "should" work down to 3.0. I wouldn't guarantee it's right for PowerShell 2.0 though.

I can't convert it into a batch script, I never learnt Windows batch scripting (I really don't like it). Even if you did convert it you'd have to figure out how to remotely execute it (psexec, perhaps), and convert the results into something presentable (batch will only work with strings). Basically it becomes a completely different problem.
Avatar of SAM IT

ASKER

thanks for response
Avatar of SAM IT

ASKER

can we build the script using WMI so we can run against 2003 servers...