【发布时间】:2017-11-03 06:28:41
【问题描述】:
我有一个集群的 DNS 名称,该集群上运行服务的节点很少。 我首先编写了 powershell 脚本,它为我提供了正在运行所提供服务的节点及其状态。脚本使用 Get-ClusterResource 命令 然后我写了执行这个powershell的python脚本。 当我运行 powershell 脚本时,我正在获取节点及其状态。但是,当我从 python 运行 powershell 脚本时,我收到以下错误:
Get-ClusterResource : The term 'Get-ClusterResource' is not recognized as the
name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is
correct and try again.
我尝试使用import-module failovercluster,但没有成功。
请让我知道我错在哪里,如果不可能,那么我正在寻找 python lib 来实现同样的目标。
我对集群的一些理解:
- 我们不能create PSSession 用于集群。
我正在以这种方式运行 powershell 脚本:
subprocess.check_output(["powershell.exe", '-ExecutionPolicy', 'Unrestricted', self.win_cluster_handling() + " -Cluster_Name " + self.cluster_name + " -ClusterNode_Action Stop-Cluster" + " -Service_Name " + self.service_name + " -Username " + self.username + " -Password " + self.password])
【问题讨论】:
-
您从 Python 运行的 PowerShell“脚本”是否只是单个命令:
powershell.exe -Command "Get-ClusterResource"(或类似命令)? -
是的。这是一个命令,powershell.exe,然后将一些参数传递给它,ps1 接受并给出结果。 Insode ps1 我有命令 Get-CLusterResource
-
啊,好的,所以你调用的是一个实际的脚本,而不仅仅是一个命令。请编辑您的原始帖子并将 Python 中的代码行放在那里(而不是在下面答案的 cmets 中)。
-
您是否尝试使用 python 脚本远程查询集群?您是在运行 python 脚本的同一台机器上测试 PowerShell 脚本吗?
-
完成。谢谢你的建议。
标签: python-2.7 python-3.x powershell powershell-3.0 powershell-remoting