如何使用PowerShell工作流通过远程PowerShell与Exchange Online进行交互,并利用并行foreach,重试等工作流功能?
#我永远找不到这方面的具体例子,最后让它工作,所以我想分享。此PowerShell工作流允许您并行查询Exchange Online(也可以是本地Exchange),自动重试错误和限制本身。
希望这对其他人有益(并且是发布问题/答案的适当方式),如果您有其他使用远程处理的PowerShell工作流示例,我很乐意看到它们。
答案 0 :(得分:2)
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 `
}
}