Note that there are some explanatory texts on larger screens.

plurals
  1. POPowerShell Workflow Exchange Remoting
    text
    copied!<p>I'm attempting to pull data from Office 365 Exchange Online in parallel to save time. I'm not able to accomplish what I'm looking to do, the following code is the "closest" I've come so far.</p> <pre><code>Workflow Get-MailboxStatisticsParallel{ param ($o365cred) $session = InlineScript { New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $using:o365cred -Authentication Basic -AllowRedirection } InlineScript { Invoke-Command -Session $session -ScriptBlock {Get-Mailbox "Firstname Middleinitial. Lastname"} } } </code></pre> <p>I defined two inline scripts because I want to setup the remote session once but then call the Get-Mailbox command in parallel to speed up the process. Here is an example of what I would want the workflow to look like.</p> <pre><code>Workflow Get-MailboxStatisticsParallel{ param ($o365cred, $mailboxes) $session = InlineScript { New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $using:o365cred -Authentication Basic -AllowRedirection } ForEach -Parallel ($mailbox in $mailboxes){ InlineScript { Invoke-Command -Session $using:session -ScriptBlock {param ($mailbox); Get-MailboxStatistics $mailbox.UserPrincipalName} -ArgumentList $mailbox } } } </code></pre> <p>An example run would look like this.</p> <pre><code>$cred = Get-Credential $mailboxes = Get-Mailbox -ResultSize Unlimited Get-MailboxStatisticsParallel -o365cred $cred -mailboxes $mailboxes </code></pre> <p>Here are the typical results.</p> <pre><code>Invoke-Command : Cannot validate argument on parameter 'Session'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. At Get-MailboxStatisticsParallel:7 char:7 + + CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand + PSComputerName : [localhost] </code></pre> <p>I can see the $session object is being deserialized, I'm guessing that's my issue. The question is how can I establish a remote PowerShell session with a specific Uri and ConfigurationName and take advantage of the features workflows provide?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload