re-using a Pshell process for frequently occurring tasks

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Windows LiveUser2 Windows LiveUser2 2 years, 1 month ago.

  • Author
    Posts
  • #25921
    Profile photo of Windows LiveUser2
    Windows LiveUser2
    Participant

    Hello,

    I've provided my company with a few scripts for a provisioning and out-processing Exchange 2010 mailboxes. It appears that there are large batches of work to do that are triggering a new Pshell process for each request, which is in turn using a lot of resources. I would like to refine the scripts to be more efficient. My thoughts were to run the scripts as jobs and close the process immediately, somehow have each task make use of an existing process, or maybe reuse an implicit remote session if that would help.

    Any feedback is greatly appreciated!

    Thanks,
    Matt

  • #25922
    Profile photo of Windows LiveUser2
    Windows LiveUser2
    Participant

    I posted on Technet too, and got a response saaying it was too vague. So here's some more info from my other thread: https://social.technet.microsoft.com/Forums/en-US/2ba1387d-80ff-43d5-a775-d8c965b9ada5/reusing-a-powershell-process-for-frequently-occurring-tasks?forum=ITCG
    ===================================

    Sorry, I'm quite new to pshell, and I didn't think I would need to provide too much detail for this. We have an application that triggers a Pshell script. It's being triggered very frequently and the number of Pshell processes are building up and stressing the server. I thought the answer may be along the lines of methods of using Pshell in general, rather than specific to a script. Exchange is a factor because of how you remote and use it's cmdlets, so I included that. Here is the script. Let me know what else I can tell you.

    ==================================

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto

    If ((Get-Mailbox -identity $A).LitigationHoldEnabled){

    If ($R = New-MailboxExportRequest -Name "$($A)-My-LitHold" -BatchName My-LitHold -Mailbox $A -FilePath \\server1\d$\folder1\$A-My-LitHoldExport.PST -AcceptLargeDataLoss -BadItemLimit 2147483647 | fl Status,Suspend,Name,FilePath,Mailbox,SourceDatabase | Out-String){

    Send-MailMessage -From LitigationHoldExporter@domain.com -SmtpServer exchange.domain.com -To joe@domain.com -Subject "Litigation Hold Export Started for $($A)" -Body "Contact the Messaging Team to investigate any problems.

    $R"
    }

    Else {Send-MailMessage -From LitigationHoldExporter@domain.com -SmtpServer exchange.domain.com -To joe@domain.com -Subject "Litigation Hold Export Started for $($A)" -Body "The Mailbox export failed to start for $($A). Forward this message to the Messaging Team to investigate.

    $R"
    }

    }
    Else{Write-Host "Mailbox $($a) is not on litigation hold"}

    ==================================

You must be logged in to reply to this topic.