none
Issue With Remote Exchange Connection Via PowerShell RRS feed

  • Question

  • Hello All,

     I am connecting Exchange 2016 server remotely via PS script to manage the Mailbox rules for users, we have close to 1500 users for which we have to create/modify mailbox rules however when i run the script (from non exchange server) which first import the exchange session to powershell and then execute the commands to manage mailbox rules but it fails after running properly for a few users with the message "Get-InboxRule/ New-InboxRule" is not is not recognized as the name of a cmdlet, function, script file, or operable program". i.e it is trying to execute the command before it imports the exchange cmdlet into powershell, please note when i run it for a few users only it will work properly.

    i have also provided delay in the PS script just after import exchange session/cmdlets command but it didn't help.

    sample PS script code:

    $username = "xyz"

    $password = get-content D:\password.txt | convertto-securestring 

    $cred = new-object System.Management.Automation.PSCredential -argumentlist $username, $password

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri url -Credential $cred

    Import-PSSession $Session

    Start-Sleep -s 10

    Rest commands to Manage Mailbox

     Note- i am using the proper url in -ConnectionUri, here it is not accepting url to be included in body so i am replacing my url with simply a name "url" :)

     

    I have to call the script one by one for each user, hence the one time connection to exchange will not work. also i tried to increase the sleep interval value but no significant improvement i observed. please find the below error logs:

    09/20/2017 04:11:23: AddInboxRule: Error while creating new BannerEclassInboxRule for uid: ogliah The term 'Get-InboxRule' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. The term 'new-inboxrule' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. The term 'Get-InboxRule' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Cannot validate argument on parameter 'Session'. The argument is null. Supply a non-null argument and try the command again. [server name] Processing data from remote server failed with the following error message: [ClientAccessServer=xxxx,BackEndServer=xxxx,RequestId=8144e36f-8a53-40f3-b613-5c50f7fbbd79,TimeStamp=9/20/2017 8:11:15 AM] [AuthZRequestId=0c78e357-fa1e-4aa9-b423-f1068e6f4e1f][FailureCategory=AuthZ-AuthorizationException] Fail to create a runspace because you have exceeded the maximum number of connections allowed : 18 for the policy party : MaxConcurrency. Please close existing runspace and try again.
    Policy: CN=GlobalThrottlingPolicy_0a68e357-3795-40ac-9b6f-3153631815a2,CN=Global Settings,CN=qauo,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=qa,DC=adroot; 
    Snapshot: Owner: Sid~S-1-5-21-2497944018-2029366656-2735507429-17592~WSMan~false
    BudgetType: WSMan
    ActiveRunspaces: 18/18
    Balance: $null/2147483647/0
    PowerShellCmdlets"white-space:pre;"> 9223372036854775807/Unlimited
    ExchangeCmdlets"white-space:pre;"> 9223372036854775807/Unlimited
    CmdletTimePeriod: Unlimited
    DestructiveCmdlets"white-space:pre;"> 9223372036854775807/Unlimited
    DestructiveCmdletTimePeriod: Unlimited
    QueueDepth: Unlimited
    MaxRunspacesTimePeriod: Unlimited
    RunSpacesRemaining: 9223372036854775807/Unlimited
    LastTimeFrameUpdate: 2017-09-20 8:06:48 AM
    LastTimeFrameUpdateDestructiveCmdlets: 2017-09-20 8:06:48 AM
    LastTimeFrameUpdateMaxRunspaces: 2017-09-20 8:06:48 AM

     
    I am new to Exchange & PowerShell hence Any help/suggestions will be great, Thanks


    • Edited by Viksss Wednesday, September 20, 2017 10:32 AM
    Wednesday, September 20, 2017 9:43 AM