Powershell 使用中央服务器在远程服务器上运行Get ClusterGroup

Powershell 使用中央服务器在远程服务器上运行Get ClusterGroup,powershell,automation,cluster-computing,powershell-2.0,Powershell,Automation,Cluster Computing,Powershell 2.0,我有一个集中式服务器,可以从中运行以下PowerShell命令以获取集群服务器的clustergroup Enter-pssession -computername (ip-address) -credential (domain user) 它会提示我输入密码,然后获取会话并执行 get-clustergroup 好吧,在这之前一切都很好 现在,我想通过将其转换为PowerShell脚本来实现完全自动化 当我在Powershell ISE中运行它并获得get clustergroup $p

我有一个集中式服务器,可以从中运行以下PowerShell命令以获取集群服务器的clustergroup

Enter-pssession -computername (ip-address) -credential (domain user)
它会提示我输入密码,然后获取会话并执行

get-clustergroup
好吧,在这之前一切都很好

现在,我想通过将其转换为PowerShell脚本来实现完全自动化

当我在Powershell ISE中运行它并获得
get clustergroup

$password = ConvertTo-SecureString "password" -AsPlainText -Force
$user = "domain\user"
$cred = New-Object System.Management.Automation.PSCredential ($user,$password)

Enter-PSSession -ComputerName IP.Add.RE.SS -Credential $cred

get-clustergroup 
但是,当我保存about脚本并使用PowerShell运行时,会出现以下错误

get-clustergroup:群集服务未运行

我想通过编写脚本来获取四台集群服务器的
getclustergroup
输出,从而自动化该过程

Enter-pssession -computername (ip-address) -credential (domain user)

我不熟悉PowerShell脚本。如何保存输出?

您可以运行以下命令,在远程计算机上运行该命令,并将输出返回到控制台,而不是创建到其他服务器的会话:

Invoke-Command -ComputerName <IPAddress> -ScriptBlock { Get-ClusterGroup } -Credential $cred
您的计算机名也可以作为数组存储在变量中。然后该变量可用于
-ComputerName
参数:

$Computers = "Server1","Server2","Server3","Server4"
Invoke-Command -ComputerName $Computers -ScriptBlock { Get-ClusterGroup } -Credential $cred

有关详细信息,请参阅。

您可以运行以下命令,而不是创建到其他服务器的会话,该命令将在远程计算机上运行,并将输出返回到控制台:

Invoke-Command -ComputerName <IPAddress> -ScriptBlock { Get-ClusterGroup } -Credential $cred
您的计算机名也可以作为数组存储在变量中。然后该变量可用于
-ComputerName
参数:

$Computers = "Server1","Server2","Server3","Server4"
Invoke-Command -ComputerName $Computers -ScriptBlock { Get-ClusterGroup } -Credential $cred

有关更多信息,请参阅。

此解决方案是否需要在PowerShell v2中?您的PowerShell控制台窗口的外观至少表明源服务器上存在其他问题。此解决方案是否需要在PowerShell v2中?PowerShell控制台窗口的外观表明至少在源服务器上是这样。