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
IF I add csv path for multiple servers its not working
__________________________
Invoke-Command -scriptblock { iisreset /status } -computername C:\Users\test\users.csv
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
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).
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
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)
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
ASKER
please find the attached scree shot , for similar command getting out put with computername
test.jpg
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 :)
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Thank you so much . If you are at twitter I will become a fan of you
Thanks for support.
ASKER
Best solution
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.
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.
ASKER
thanks for response
ASKER
can we build the script using WMI so we can run against 2003 servers...
If the CSV file had a column named ComputerName, which contained the list, you could use:
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.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[]).