PowerShell 工作流 - InlineScript 远程处理 [英] PowerShell Workflow - InlineScript Remoting

查看:26
本文介绍了PowerShell 工作流 - InlineScript 远程处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 PowerShell 工作流通过远程 PowerShell 与 Exchange Online 交互,并利用并行 foreach、重试等工作流功能?

How can you use PowerShell workflows to interact with Exchange Online via remote PowerShell and take advantage of the workflow features such as parallel foreach, retries, etc.?

我永远找不到具体的例子,但终于让它工作了,所以我想分享一下.此 PowerShell 工作流允许您并行查询 Exchange Online(也可以是本地 Exchange),自动重试错误并自我限制.

I could never find specific examples of this and finally got it working so I wanted to share. This PowerShell workflow allows you to query Exchange Online (could be Exchange on-premises as well) in parallel, automatically retries on error and throttles itself.

希望这对其他人有益(并且是发布问题/答案的合适方式),如果您有其他使用远程处理的 PowerShell 工作流示例,我很乐意看到它们.

Hopefully this is of benefit to others (and is an appropriate way to post a question/answer), if you have other examples of PowerShell workflows using remoting I would love to see them.

推荐答案

workflow Test-ExchangeQuery {
    <#
    .Synopsis
       Short description
    .DESCRIPTION
       Long description
    .EXAMPLE
       Example of how to use this cmdlet
    .EXAMPLE
       Another example of how to use this cmdlet
    #>
    Param
    (
        # Username of account
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        [string[]]
        $Identity,

        # Exchange / AD Credentials
        [Parameter(Mandatory=$true)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential
    )

    Set-PSWorkFlowData -PSAllowRedirection $true

    ForEach -Parallel -ThrottleLimit (2) ($user in $Identity) {
        InlineScript {
            Get-Mailbox -Identity $using:user | Select-Object Name, PrimarySmtpAddress
        } -DisplayName "Querying Exchange" `
            -PSCredential $Credential `
            -PSConnectionUri "https://ps.outlook.com/powershell/" `
            -PSConfigurationName "Microsoft.Exchange" `
            -PSComputerName $null `
            -PSAuthentication Basic `
            -PSConnectionRetryCount 3 `
    }
}

这篇关于PowerShell 工作流 - InlineScript 远程处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆