如何从.ps1文件运行Powershell命令?

时间:2019-09-18 03:49:35

标签: azure powershell cmdlets

我有以下内容:

$command = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$arguments = @('Set-AzLogicApp -ResourceGroupName "MyResourceGroup" -Name "MyLogicAppName" -State "Disabled" -Force')
& $command $arguments

当我从命令运行它时,它说Set-AzLogicApp : The term 'Set-AzLogicApp' is not recognized as the name of a cmdlet

这是什么原因?

2 个答案:

答案 0 :(得分:0)

很抱歉,我必须运行Install-Module -Name Az。感谢您的所有帮助

答案 1 :(得分:0)

我想了解为什么您要从.ps1文件中调用Powershell.exe。无论如何,如果您正在执行PS文件,则所有已安装的模块都可以执行。您只需导入模块并运行命令即可。

此外,您还必须按照在计算机中安装后提到的Joy的方式导入Az.LogicApp。

代码如下所示:

Import-Module -Name "Az.LogicApp"
$command = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$arguments = @('Set-AzLogicApp -ResourceGroupName "MyResourceGroup" -Name "MyLogicAppName" -State "Disabled" -Force')
& $command $arguments

enter image description here

我尽力了,对我有用。请尝试让我知道是否需要任何进一步的帮助。