Answered by:
Test Exchange Services on all servers one cmd

Question
-
Guys is there any way i can run the below in one cmd as i tried but getting a below error i am try to check the exchange services from one cmd let instead of simple script
----------------------------------
$ExchServer=Get-ExchangeServer
foreach ($Server in $ExchServer)
{
echo $Server.name (Test-ServiceHealth $Server)
}------------------------------------
Error***********
[PS] C:\Windows\system32>$ExchServer=Get-ExchangeServer | foreach ($Server in $ExchServer) {echo $Server.name (Test-ServiceHealth $Server)}
Unexpected token 'in' in expression or statement.
At line:1 char:53
+ $ExchServer=Get-ExchangeServer | foreach ($Server in <<<< $ExchServer) {echo $Server.name (Test-ServiceHealth $Serve
r)}
+ CategoryInfo : ParserError: (in:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken- Moved by Bill_Stewart Sunday, July 27, 2014 3:17 PM Abandoned
Thursday, June 26, 2014 3:06 AM
Answers
-
Actually it needs one small tweek:
Get-ExchangeServer | foreach{ $server=$_.Name Test-ServiceHealth $_ |Add-Member NoteProperty ServerName $server -PassThru } | Select *
The Test-ServerHealth command returns multiple records per server (one per role) and they are not tagged as to which server they refer.
¯\_(ツ)_/¯
Thursday, June 26, 2014 9:09 AM
All replies
-
Hi Jugal,
what you ran is not identical with what you posted. You can either try running the code you posted in bold, or ...
Get-ExchangeServer | foreach {echo $_.name (Test-ServiceHealth $_)}
Cheers,
FredThere's no place like 127.0.0.1
Thursday, June 26, 2014 6:40 AM -
Actually it needs one small tweek:
Get-ExchangeServer | foreach{ $server=$_.Name Test-ServiceHealth $_ |Add-Member NoteProperty ServerName $server -PassThru } | Select *
The Test-ServerHealth command returns multiple records per server (one per role) and they are not tagged as to which server they refer.
¯\_(ツ)_/¯
Thursday, June 26, 2014 9:09 AM -
I think the question is really this: "How do I do this and return only one object?" I do not think the user is asking how to do this in one command. It cannot be done in one command and there is no point in doing it on only one line.
¯\_(ツ)_/¯
- Edited by jrv Thursday, June 26, 2014 9:12 AM
Thursday, June 26, 2014 9:11 AM -
Sorry jrv and FWN getting below error while running.
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
PSInvalidOperationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailedFriday, June 27, 2014 3:31 AM -
As I said above. It cannot be done in one command or pipeline. Do it in steps.
¯\_(ツ)_/¯
Friday, June 27, 2014 4:15 AM