0

Now that AWS Lambda supports PowerShell core according to this blog, has anybody tried running PowerShell commands to create Mailbox in Hybrid env(run PS cmdlets in both On-prem and office 365 env) using lambda? I couldn't find anything online which does that. Most of the Lambda Powershell usecases seems to be related to using PowerShell scripts to automate and manage AWS resources. I'm working on a POC for a REST service which does all of the mailbox creation operations and was planning to use API gateway to invoke lambda powershell.

I did setup my environment following aws documentation and created a PowerShell script which performs mailbox operation and created and deployed lambda. Upon testing, i'm getting the following errors while creating a PowerShell session for O365 env.

Script snippet:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $mycreds -Authentication Basic -AllowRedirection
Write-Host "Created session for PS"
Import-PSSession $Session
Write-Host "Imported Session"
Write-Host "Getting Mailbox"
Get-Mailbox -Identity 'mailbox'

Cloudwatch Logs:

[Error] - This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.
[Information] - Created session for PS
[Error] - Cannot validate argument on parameter 'Session'. The argument is null. Provide a valid value for the argument, and then try running the command again.
[Information] - Imported Session
[Information] - Getting Mailbox
[Error] - The term 'Get-Mailbox' 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.

Wondering if anyone has tried invoking Office 365/on-prem mailbox creation PS scripts using lambda or point me to the right direction? Thanks

I would also like to know, if with AWS lambda powershell core can i winrm into another windows box so that i can execute powershell mailbox commands? According to the ans dated in 10/2018 we cannot, but wondering if anyone knows anything latest on this.

1 Answer 1

0

I am working the same task. API->Lambda->C#/PowerShell->Office360->CreateMailbox. However I'm hung up on the same line as well, but slightly different message.

What do you have for a Requires line in your ps1 file?

Requires -Modules @{ModuleName='AWS.Tools.Common';ModuleVersion='4.0.5.0'}

I am assuming you are using ModuleVersion='3.3.618.0' per the linked blog post, but there is a '4.0.5.0' version available. ... However it hasn't help me yet, but perhaps it would help you. Here is link with the upgrade information. https://docs.aws.amazon.com/powershell/latest/userguide/v4migration.html

Sign up to request clarification or add additional context in comments.

3 Comments

I'm using 4.0.5.0 as well. According to github.com/aws/aws-lambda-dotnet/issues/368 we cannot achieve that with Lambda. I'm going in an alternate path of API->Lambda->SSM Doc->SSM Run command->PS on Win Ec2 instance. Not ideal but i think this will work.
Sadly I found similar posts. The only successful story is captured here, forums.aws.amazon.com/thread.jspa?messageID=940410#940410. However, I have yet to duplicate that success story. I can't seem to get my hands on those missing libraries.
I saw that post earlier, in my case those dependencies were already getting packaged together. More over i did not see the error "Unable to load shared library 'libpsrpclient' or one of its dependencies". It was more of a "This parameter set requires WSMan, and no supported WSMan client library was found." Let me know if you figure it out. Good Luck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.