我尝试从 Azure 函数中的 AAD 获取所有用户,如 [this][1] 教程中所示,但出现错误:
当前的处理器架构是:X86。模块“C:\home\data\ManagedDependency�2280958333475556.r\AzureAD .0.2.182\AzureAD.psd1”需要以下体系结构:Amd64。
运行.ps1
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
Import-Module AzureAD -UseWindowsPowerShell
Connect-AzAccount -Identity
$allUsers = Get-AzureADUser -All $True
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
要求.psd1
# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
'Az.Accounts' = '2.5.4'
'AzureAD' = '2.*'
}
我正在使用 PowerShell 7 和 Azure 函数中的托管标识。托管身份具有读取权限,如下面的打印屏幕所示。
我尝试运行 Azure 函数并期望获得包含所有 AAD 用户的列表。我收到此日志,其中包含一些错误和警告:
[这是第一个错误的打印屏幕][2]
[当我向下滚动时,我看到第二个错误][3]
Exception :
Type : System.Management.Automation.RemoteException
SerializedRemoteException : System.InvalidOperationException: The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
ErrorRecord :
Exception :
Type : System.Management.Automation.RemoteException
SerializedRemoteException : System.InvalidOperationException: The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
ErrorRecord :
Exception :
Type : System.Management.Automation.RemoteException
SerializedRemoteException : System.InvalidOperationException: The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
ErrorRecord :
Exception :
Type : System.Management.Automation.RemoteException
SerializedRemoteException : System.InvalidOperationException: The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
ErrorRecord :
Exception :
Type : System.Management.Automation.RemoteException
SerializedRemoteException : System.InvalidOperationException: The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
ErrorRecord : …
Message : The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
HResult : -2146233087
TargetObject : C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1
CategoryInfo : ResourceUnavailable: (C:\home\data\Manage….2.182\AzureAD.psd1:String) [Import-Module], InvalidOperationException
FullyQualifiedErrorId : Modules_InvalidProcessorArchitecture,Microsoft.PowerShell.Commands.ImportModuleCommand
Message : The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
HResult : -2146233087
TargetObject : C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1
CategoryInfo : ResourceUnavailable: (C:\home\data\Manage….2.182\AzureAD.psd1:String) [Import-Module], InvalidOperationException
FullyQualifiedErrorId : Modules_InvalidProcessorArchitecture,Microsoft.PowerShell.Commands.ImportModuleCommand
Message : The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
HResult : -2146233087
TargetObject : C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1
CategoryInfo : ResourceUnavailable: (C:\home\data\Manage….2.182\AzureAD.psd1:String) [Import-Module], InvalidOperationException
FullyQualifiedErrorId : Modules_InvalidProcessorArchitecture,Microsoft.PowerShell.Commands.ImportModuleCommand
Message : The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
HResult : -2146233087
TargetObject : C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1
CategoryInfo : ResourceUnavailable: (C:\home\data\Manage….2.182\AzureAD.psd1:String) [Import-Module], InvalidOperationException
FullyQualifiedErrorId : Modules_InvalidProcessorArchitecture,Microsoft.PowerShell.Commands.ImportModuleCommand
Message : The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
HResult : -2146233087
TargetObject : C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1
CategoryInfo : ResourceUnavailable: (C:\home\data\Manage….2.182\AzureAD.psd1:String) [Import-Module], InvalidOperationException
FullyQualifiedErrorId : Modules_InvalidProcessorArchitecture,Microsoft.PowerShell.Commands.ImportModuleCommand
ErrorDetails : Failure from remote command: Import-Module -Name 'AzureAD': The current processor architecture is: X86. The module 'C:\home\data\ManagedDependencies\2312280958333475556.r\AzureAD\2.0.2.182\AzureAD.psd1' requires the following architecture: Amd64.
InvocationInfo :
MyCommand : Import-Module
ScriptLineNumber : 6
OffsetInLine : 1
HistoryId : 1
ScriptName : C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1
Line : Import-Module AzureAD -UseWindowsPowerShell
PositionMessage : At C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1:6 char:1
+ Import-Module AzureAD -UseWindowsPowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : C:\home\site\wwwroot\GetAllAadGroupMembers
PSCommandPath : C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1
InvocationName : Import-Module
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1: line 6
PipelineIterationInfo :
2023-12-28T12:47:57Z [Information] OUTPUT:
2023-12-28T12:48:00Z [Warning] The Function app may be missing a module containing the 'Get-AzureADUser' command definition. If this command belongs to a module available on the PowerShell Gallery, add a reference to this module to requirements.psd1. Make sure this module is compatible with PowerShell 7. For more details, see https://aka.ms/functions-powershell-managed-dependency. If the module is installed but you are still getting this error, try to import the module explicitly by invoking Import-Module just before the command that produces the error: this will not fix the issue but will expose the root cause.
2023-12-28T12:48:00Z [Error] ERROR: The term 'Get-AzureADUser' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Exception :
Type : System.Management.Automation.CommandNotFoundException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : The term 'Get-AzureADUser' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
HResult : -2146233087
TargetObject : Get-AzureADUser
CategoryInfo : ObjectNotFound: (Get-AzureADUser:String) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : CommandNotFoundException
InvocationInfo :
ScriptLineNumber : 8
OffsetInLine : 13
HistoryId : 1
ScriptName : C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1
Line : $allUsers = Get-AzureADUser -All $True
PositionMessage : At C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1:8 char:13
+ $allUsers = Get-AzureADUser -All $True
+ ~~~~~~~~~~~~~~~
PSScriptRoot : C:\home\site\wwwroot\GetAllAadGroupMembers
PSCommandPath : C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1
InvocationName : Get-AzureADUser
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1: line 8
CommandName : Get-AzureADUser
TargetSite :
Name : LookupCommandInfo
DeclaringType : System.Management.Automation.CommandDiscovery, System.Management.Automation, Version=7.2.13.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
Message : The term 'Get-AzureADUser' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Data : System.Collections.ListDictionaryInternal
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)
at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject : Get-AzureADUser
CategoryInfo : ObjectNotFound: (Get-AzureADUser:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
InvocationInfo :
ScriptLineNumber : 8
OffsetInLine : 13
HistoryId : 1
ScriptName : C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1
Line : $allUsers = Get-AzureADUser -All $True
PositionMessage : At C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1:8 char:13
+ $allUsers = Get-AzureADUser -All $True
+ ~~~~~~~~~~~~~~~
PSScriptRoot : C:\home\site\wwwroot\GetAllAadGroupMembers
PSCommandPath : C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1
InvocationName : Get-AzureADUser
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, C:\home\site\wwwroot\GetAllAadGroupMembers\run.ps1: line 8
2023-12-28T12:48:00Z [Information] OUTPUT: Account SubscriptionName TenantId Environment
2023-12-28T12:48:00Z [Information] OUTPUT: ------- ---------------- -------- -----------
2023-12-28T12:48:00Z [Information] OUTPUT: MSI@50342 azt101nsub0000 7c942460-5c3c-4314-8894-f4f09e5dd09b AzureCloud
2023-12-28T12:48:00Z [Information] OUTPUT:
2023-12-28T12:48:00Z [Information] Executed 'Functions.GetAllAadGroupMembers' (Succeeded, Id=aebec362-b245-4636-b253-25cba1c10d4e, Duration=3531ms)```
[1]: https://github.com/brettmillerb/azureadFunction/tree/main
[2]: https://i.stack.imgur.com/d3H5W.png
[3]: https://i.stack.imgur.com/YAyzX.png
当前的处理器架构是:X86。该模块 “C:\home\data\ManagedDependency�2280958333475556.r\AzureAD .0.2.182\AzureAD.psd1”需要以下体系结构:Amd64。
要解决此错误,您需要更新 Function App 中的以下设置。
Function App> Configuration > General Settings > Platform > 64 Bit
我正在使用以下代码。
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
Import-Module AzureAD -UseWindowsPowerShell
Connect-AzureAD
$allUsers = Get-AzureADUser -All $True
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
输出-