我正在尝试通过Azure ARM模板执行以下PowerShell脚本(下面的片段),
Install-Module -Name AzureAD -force
Import-Module -Name AzureAD -UseWindowsPowerShell -RequiredVersion 2.0.2.89 -force
$SecurePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential($username, $SecurePassword)
Connect-AzureAD -Credential $credentials -Verbose -Debug
并得到以下错误。
{
"status": "failed",
"error": {
"code": "DeploymentScriptError",
"message": "The provided script failed with the following error:\r\nSystem.Management.Automation.CommandNotFoundException: The term 'Connect-AzureAD' is not recognized as a name of a cmdlet, function, script file, or executable program.\nCheck the spelling of the name, or if a path was included, verify that the path is correct and try again.\n at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)\n at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)\n at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\n at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\n at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)\n at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)\n at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)\n at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)\n at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)\n at System.Management.Automation.ScriptBlock.InvokeUsingCmdlet(Cmdlet contextCmdlet, Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args)\n at Microsoft.PowerShell.Commands.InvokeExpressionCommand.ProcessRecord()\n at System.Management.Automation.Cmdlet.DoProcessRecord()\n at System.Management.Automation.CommandProcessor.ProcessRecord()\r\nat <ScriptBlock>, /mnt/azscripts/azscriptinput/removeappregistrationurl.ps1: line 33\r\nat <ScriptBlock>, <No file>: line 1\r\nat <ScriptBlock>, /mnt/azscripts/azscriptinput/DeploymentScript.ps1: line 295. Please refer to https://aka.ms/DeploymentScriptsTroubleshoot for more deployment script information."
}
}
ARM模板片段
{
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "2020-10-01",
"name": "RemoveAppRegistrationUrl",
"location": "eastus",
"kind": "AzurePowerShell",
"properties": {
"forceUpdateTag": "1",
"containerSettings": {
"containerGroupName": "parsagecustomaci"
},
"azPowerShellVersion": "7.2",
"arguments": "[concat(' -pUid ',parameters('UserId'),' -pPassword ',parameters('Password'),' -appId ',parameters('AppId'), ' -objId ', parameters('ObjectId'), ' -replyUrlToRemove ', parameters('ReplyUrlToRemove'))]",
"primaryScriptUri": "https://saproliosaasdev.blob.core.windows.net/armtemplates/removeappregistrationurl.ps1",
"supportingScriptUris": [],
"timeout": "PT30M",
"cleanupPreference": "OnSuccess",
"retentionInterval": "P1D"
}
}
我能够从本地powershell示例和Azure Cloud Shell运行命令,没有任何问题。
1条答案
按热度按时间nkoocmlb1#
术语“Connect-AzureAD”无法识别为cmdlet、函数、脚本文件或可执行程序的名称。\n请检查名称的拼写。
如果未正确导入AzureAD模块,则错误消息表示您的计算机上未安装Connect-AzureAD。
您可以按照以下步骤排除Azure AD模块的故障。
1.您可以通过运行以下命令来验证AzureAD模块是否安装正确。
Get-Installedmodule | Where-Object {$_.Name -match "AzureAD"}
您还可以使用以下命令验证系统上是否存在Connect-AzureADcmdlet。
1.如果未列出该模块,则需要使用以下命令安装它
安装模块名称AzureAD
确保通过输入**“A”- Yes to All**确认安装。
1.安装模块后,请确保使用以下命令导入该模块
Import-Module -Name AzureAD
1.使用以下命令更新AzureAD模块
1.更新AzureAD模块后,请尝试运行Connect-AzureAD。