Jobs and Variables

Welcome Forums General PowerShell Q&A Jobs and Variables

This topic contains 3 replies, has 3 voices, and was last updated by

4 months, 2 weeks ago.

  • Author
  • #129377

    Topics: 2
    Replies: 7
    Points: 71
    Rank: Member

    I am trying to get a report from a mailboxsearch from all servers from several dags each running as a job

    I am close but need some help tuning it. The Jobs are being created but seem to be running in series.

    $USADAGS = Get-MailboxServer | Where-Object { $_.DatabaseAvailabilityGroup -like 'USA-*' } | Select-Object $DatabaseAvailabilityGroup -Unique
    Foreach ($Dag in $GDAGS){Start-Job -Name $Dag.DatabaseAvailabilityGroup -ScriptBlock {
    . $env:ExchangeInstallPath\bin\RemoteExchange.ps1
    Connect-ExchangeServer -auto -AllowClobber
    $USADAGS = Get-MailboxServer | Where-Object { $_.DatabaseAvailabilityGroup -like 'USA-*' } | Select-Object $DatabaseAvailabilityGroup -Unique
    Foreach ($Dag in $USADAGS){
    $StartDate = ((Get-Date).AddDays(1))
    $resultsize = 250000
    $servers = Get-MailboxServer | Where-Object { $_.DatabaseAvailabilityGroup -eq $Dag.DatabaseAvailabilityGroup }
    $AllServers = foreach ($server in $servers){
    Get-Mailbox -server $server.DistinguishedName -ResultSize 'unlimited'
    ForEach ($mbx in $AllServers){try{
    Search-MailboxAuditLog $mbx.alias -LogonTypes Admin, Delegate -ShowDetails -StartDate $StartDate -resultsize $resultsize -ea 'stop' |Select-Object PSComputername, Operation, LogonType, FolderPathName, ClientInfoString, ClientIPAddress, MailboxResolvedOwnerName, MailboxOwnerUPN, ItemSubject, LogonUserDisplayName, LogonUserSid, OriginatingServer, LastAccessed |Export-Csv "C:\exports\$($Dag.DatabaseAvailabilityGroup)_Search.csv" -NoTypeInformation -Append
    { Write-Output "$($mbx) on $($Dag.DatabaseAvailabilityGroup) had the error $($_).Exception.Message" |
    Out-File :\exports\$($Dag.DatabaseAvailabilityGroup)_error.log" -Append
  • #129416

    Topics: 8
    Replies: 739
    Points: 2,071
    Helping Hand
    Rank: Community Hero

    You cannot trigger background jobs in Parallel using Start-Job. Start-Job creates a PowerShell.exe process for each job, so its not recommended to use it if you have more items. You can use PoshRSJob module instead. You can have a check with Invoke-Parallel for parallel executions. Both of these are available in PowerShellGallery.

  • #129663

    Topics: 2
    Replies: 7
    Points: 71
    Rank: Member

    So what would be the best method to do a mailbox audit search nightly against 200K + mailboxes across 60 DAGs
    in a four hour window?

  • #129755

    Topics: 0
    Replies: 6
    Points: 17
    Rank: Member

    I have not read the code so I am not commenting on the code here more a possible answer to your question...Have you looked into Workflows? This may help you do what you want.

    So, I would look into workflows (using the parameter -pspersist $true) and also foreach -parallel


The topic ‘Jobs and Variables’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort