PowerShell工作流-内联脚本远程处理

PowerShell工作流-内联脚本远程处理,powershell,workflow,powershell-remoting,Powershell,Workflow,Powershell Remoting,如何使用PowerShell工作流通过远程PowerShell与Exchange联机交互,并利用工作流功能(如并行foreach、重试等) # 我一直找不到这方面的具体例子,但最终还是成功了,所以我想与大家分享。此PowerShell工作流允许您并行在线查询Exchange(也可以是内部部署的Exchange),自动重试错误并自我调节 如果您有其他使用远程处理的PowerShell工作流示例,我希望看到它们。工作流测试交换{ workflow Test-ExchangeQuery { &

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

# 我一直找不到这方面的具体例子,但最终还是成功了,所以我想与大家分享。此PowerShell工作流允许您并行在线查询Exchange(也可以是内部部署的Exchange),自动重试错误并自我调节

如果您有其他使用远程处理的PowerShell工作流示例,我希望看到它们。

工作流测试交换{
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 `
    }
}
Param ( #帐户的用户名 [参数(必需=$true, ValueFromPipelineByPropertyName=$true, 位置=0)] [字符串[]] $Identity, #交换/广告凭证 [参数(必需=$true)] [系统、管理、自动化、PSCredential] [System.Management.Automation.Credential()] $Credential ) 设置PSWorkFlowData-PSAllowerDirection$true ForEach-Parallel-ThrottleLimit(2)($Identity中的$user){ 内联脚本{ 获取邮箱-标识$using:user |选择对象名称,PrimarySmtpAddress }-DisplayName“查询交换”` -PSCredential$凭证` -PSConnectionUri“https://ps.outlook.com/powershell/" ` -PSConfigurationName“Microsoft.Exchange”` -PSComputerName$null` -PSA基本身份验证` -PSConnectionRetryCount 3` } }