【问题标题】:AWS Lambda Powershell to create mailbox in Hybrid(run powershell commands in both Office 365 and On-Prem)AWS Lambda Powershell 在混合中创建邮箱(在 Office 365 和 On-Prem 中运行 powershell 命令)
【发布时间】:2020-07-19 05:29:56
【问题描述】:

现在 AWS Lambda 根据此 blog 支持 PowerShell 核心,是否有人尝试使用 lambda 运行 PowerShell 命令以在混合环境中创建邮箱(在本地和办公室 365 环境中运行 PS cmdlet)?我在网上找不到任何可以做到这一点的东西。大多数 Lambda Powershell 用例似乎都与使用 PowerShell 脚本自动化和管理 AWS 资源有关。 我正在为 REST 服务开发 POC,该服务执行所有邮箱创建操作,并计划使用 API 网关来调用 lambda powershell。

我确实按照 aws documentation 设置了我的环境,并创建了一个执行邮箱操作并创建和部署 lambda 的 PowerShell 脚本。经过测试,我在为 O365 环境创建 PowerShell 会话时遇到以下错误。

脚本 sn-p:

    $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 日志:

[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.

想知道是否有人尝试过使用 lambda 调用 Office 365/on-prem 邮箱创建 PS 脚本或指出正确的方向?谢谢

我也想知道,如果使用 AWS lambda powershell core,我是否可以将 winrm 进入另一个 windows 框,以便我可以执行 powershell 邮箱命令?根据 2018 年 10 月的 ans,我们不能,但想知道是否有人知道这方面的最新消息。

【问题讨论】:

    标签: amazon-web-services powershell aws-lambda office365 powershell-core


    【解决方案1】:

    我正在做同样的工作。 API->Lambda->C#/PowerShell->Office360->CreateMailbox。 不过我也挂在同一条线上,但信息略有不同。

    您的 ps1 文件中的 Requires 行是什么?

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

    我假设您在链接的博客文章中使用 ModuleVersion='3.3.618.0',但有一个 '4.0.5.0' 版本可用。 ... 但是它还没有帮助我,但也许它会帮助你。这是升级信息的链接。 https://docs.aws.amazon.com/powershell/latest/userguide/v4migration.html

    【讨论】:

    • 我也在使用 4.0.5.0。根据github.com/aws/aws-lambda-dotnet/issues/368,我们无法使用 Lambda 实现这一目标。我将在 Win Ec2 实例上使用 API->Lambda->SSM Doc->SSM Run command->PS 的替代路径。不理想,但我认为这会奏效。
    • 遗憾的是我发现了类似的帖子。这里记录了唯一成功的故事,forums.aws.amazon.com/thread.jspa?messageID=940410#940410。然而,我还没有复制那个成功的故事。我似乎无法找到那些丢失的库。
    • 我之前看过那篇文章,在我的例子中,这些依赖项已经打包在一起了。此外,我没有看到错误“无法加载共享库'libpsrpclient'或其依赖项之一”。它更像是“这个参数集需要 WSMan,并且没有找到支持的 WSMan 客户端库”。让我知道你是否知道。祝你好运
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    相关资源
    最近更新 更多