Powershell Lambda for AD failing with "A parameter cannot be found that matches parameter name 'Culture'"

0

I am attempting to create a Powershell Lambda, which runs this script to alert AD users of expiring passwords via SES: #Requires –Modules ActiveDirectory #Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.283.0'} $pwd = ConvertTo-SecureString 'XXXXXXXXX' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential('XXXXXXXXXXX', $pwd) Get-ADUser -Filter * -Server XXXXXXXXXX -SearchBase "OU=User,OU=TestADManagement,OU=TestOU,DC=XXXXXXXXXXX,DC=com" -Properties Name, mail, Enabled, AccountExpirationDate, AccountExpires, msDS-UserPasswordExpiryTimeComputed -Credential $cred | Select-Object -Property Name, mail, AccountExpirationDate, AccountExpires, Enabled, @{Name="PasswordExpiry"; Expression={[datetime]::FromFileTime($."msDS-UserPasswordExpiryTimeComputed")}} | Where-Object {(($.AccountExpirationDate -gt (Get-Date)) -or ($.AccountExpires -eq '0') -or ($.AccountExpires -eq '9223372036854775807')) -and $.Enabled -eq $true -and ($.PasswordExpiry -lt ((Get-Date).AddDays(87))) -and $.PasswordExpiry -notlike "12/31/1600*" } | ForEach-Object {$timediff = New-Timespan -Start (Get-Date) -End $.PasswordExpiry; Send-SES2Email -FromEmailAddress "sergey.gankin@veolia.com" -Destination_ToAddress $.mail -Text_Data "Hello $($.Name), your password will expire in $($timediff.Days) days!" -Subject_Data "Password Expiring"}

The script itself runs successfully, the Lambda gets created and successfully hosted in a VPC, but when attempting to execute the Lambda, it throws the following error:

{ "errorType": "CmdletInvocationException", "errorMessage": "A parameter cannot be found that matches parameter name 'Culture'.", "stackTrace": [ "at Amazon.Lambda.PowerShellHost.PowerShellFunctionHost.ExecuteFunction(Stream inputStream, ILambdaContext context)", "at lambda_method18(Closure , Stream , ILambdaContext , Stream )", "at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145", "at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 56", "at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176" ], "cause": { "errorType": "ParameterBindingException", "errorMessage": "A parameter cannot be found that matches parameter name 'Culture'.", "stackTrace": [ "at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)", "at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame)", "at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)", "at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)", "at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)", "at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)", "at System.Management.Automation.PSScriptCmdlet.RunClause(Action1 clause, Object dollarUnderbar, Object inputToProcess)", "at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()", "at System.Management.Automation.CommandProcessorBase.Complete()" ] } }

I've tired creating the Lambda with Powershell 7 and Powershell 6, but getting the same error, although the ActiveDirectory module appears to import just fine. I've also tried requiring AWSPowerShell.NetCore and AWS.Tools.Common (separately, because together, they generate a "module by this name was already loaded" error), but that made no difference, and requiring Microsoft.PowerShell.Utility, or Microsoft.PowerShell.Management makes the package too large. Please help!

1 Answer
0

As per the documentation[1], CmdletInvocationException(), Indicates that a cmdlet hit a terminating error.

From the error it seems like a parameter is not present which is giving out the error. Kindly print the event received by the handler code and verify if the parameter Culture is expected to be present in the event. If it is present, kindly, check how the code is trying to access the parameter. Please ensure that the code is searching for the parameter at the correct level in the event JSON.

Resource [1]: https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.cmdletinvocationexception?view=powershellsdk-7.0.0

AWS
SUPPORT ENGINEER
answered 2 years ago
  • Thank you, Manasvi,

    But my code is not passing any command, which requires the "Culture" parameter. It would seem, that the error is not being thrown by the Lambda itself, but by one of the library modules its leveraging - perhaps when attempting to import it. I did, in fact, see such a parameter mentioned, when i tried importing the ActiveDirectory PS module with the -SkipEditionCheck switch (this is from when i was trying different options prior to attemting to publish the Lambda, not from when I was attemting to run the Lambda itself, but perhaps it might serve as a clue):

    PS C:\Projects\AccountExpirationWarming\PwdExpirationAlertLambda> Import-Module ActiveDirectory -SkipEditionCheck Import-Module: Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation, Version=7.2.6.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

    I was able to import the module this way: Import-Module ActiveDirectory WARNING: Module ActiveDirectory is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

    I am no longer getting an error, stating that the Get-ADUser command cannot be found, but maybe Lambda throws the error, when attempting to load the module, before it ever gets to running the command?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions