Foreach循环未通过条目列表运行

时间:2018-09-18 14:40:29

标签: powershell loops foreach scripting

我已尝试多次搜索,但尚未解决问题。我在$ mediaagentlist中有一个服务器列表,foreach循环应该贯穿每个服务器并获取某些服务的状态:

    $mediaagentlist = "cs0400ma01
cs0400ma02"

[string]$Commcell_Input = $args[0] 
$MAChoice = $args[1]

if ($MAChoice -eq $null)
        {
            Write-Output "No media agent was specified, running against all MAs in the Commcell..."

            #Run this loop for each MA which is stored in Mediaagentlist
            foreach ($Mediaagent in $Mediaagentlist)
            {
                Write-Output $Mediaagent
                $GxCLMgrS_State = Invoke-Command -ComputerName $Mediaagent {Get-Service -name "GxClMgrS(Instance001)"}
                $GXMMM_State = Invoke-Command -ComputerName $Mediaagent {Get-Service -name "GXMMM(Instance001)"}
                $GxCVD_State = Invoke-Command -ComputerName $Mediaagent {Get-Service -name "GxCVD(Instance001)"}

                Write-Output "Client manager service state: " $GxCLMgrS_State.Status
                Write-Output "Media manager mount service state: " $GXMMM_State.Status
                Write-Output "Communications service state: " $GxCVD_State.Status

            }


        }

如何纠正此问题,以便for循环遍历$ mediaagentlist中的条目列表并为每个服务器运行代码?

谢谢!

1 个答案:

答案 0 :(得分:3)

您的问题似乎在这里

public interface FooRepository extends JpaRepository<Foo, Integer> { }

public interface BarRepository extends JpaRepository<Bar, Integer> { }

您似乎错过了每个单词的结尾qoute和一个逗号

尝试

$mediaagentlist = "cs0400ma01
cs0400ma02"

$mediaagentlist = "cs0400ma01", "cs0400ma02"

或者您可以定义多行字符串,然后在新行上分割(如果有原因,您需要将输入作为单个多行字符串:

$mediaagentlist = @("cs0400ma01", "cs0400ma02")