连接到故障转移群集所有者节点和 运行 PowerShell 脚本

Connect to failover cluster owner node and run PowerShell script

我有一个预定的 PowerShell 脚本,我想 运行 在特定故障转移群集角色的当前所有者节点上。

我正在尝试使用计划的 PowerShell 任务,首先询问集群,然后根据角色的所有者节点,连接并 运行 该节点上的远程 PowerShell 脚本。

这是我目前的情况:

$Role = Get-ClusterGroup -Cluster FLX-CL-CL01.cory.local -Name FLX-CL-FS01
$OwnerNode = $Role.OwnerNode
$OwnerNodeName = $OwnerNode.Name
$Credential = Get-Credential
$Session = New-PSSession -ComputerName $OwnerNodeName -Credential 
$Credential
Invoke-Command -Session $Session -ScriptBlock {
    powershell.exe -Command "\path_to_script.ps1"
}
Remove-PSSession -Session $Session

当 运行 执行此操作时,我收到拒绝访问错误,但我不太清楚什么访问被拒绝?

我确实尝试在不指定 powershell.exe -Command 的情况下放入脚本,但它说创建管道时发生错误。如果我把它放在引号中,它只会将路径输出为文本。

任何人都可以建议我应该在 -ScriptBlock 部分中使用什么语法来在远程计算机上执行此脚本吗?

通过删除 -scriptblock 并替换为 -FilePath 并后跟脚本路径,设法解决了这个问题。