none
Exchange PowerShell not running The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently. issue ?

    Question

  • Hi All,

    I need to run this PowerShell command to get the Distribution group status:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRODHT01-VM/PowerShell/ -Authentication Kerberos
    Import-PSSession $Session -AllowClobber
    Import-Module ActiveDirectory -ErrorAction STOP
    
    Function GetDLStatistics {
       Get-DistributionGroup -ResultSize Unlimited -ErrorAction SilentlyContinue | ForEach {$_.GUID} | ForEach {
     
          ## Run the Get-DistributionGroup Cmdlet
          $DLData = (Get-DistributionGroup -ErrorAction SilentlyContinue -Identity "$_")
     
          ## Run the Get-QADGroupMember Cmdlet - The @ makes sure it can count 0 and 1 values.
          $DLMembers = @(Get-ADGroupMember -Identity "$_" -ErrorAction SilentlyContinue)
     
          ## Get values from Get-DistributionGroup Cmdlet
          $ACE_DL_Alias = $DLData.Alias
          $ACE_DL_DisplayName = $DLData.DisplayName
          $ACE_DL_AcceptMessagesOnlyFrom = $DLData.AcceptMessagesOnlyFrom
          $ACE_DL_AcceptMessagesOnlyFromDLMembers = $DLData.AcceptMessagesOnlyFromDLMembers
          $ACE_DL_HiddenFromAddressListsEnabled = $DLData.HiddenFromAddressListsEnabled
     
          ## Put all values in a string separated by ^ so that it can be put into a CSV.
     
          $String =  $ACE_DL_DisplayName +"^"+ $ACE_DL_Alias +"^"+ $_ +"^"+ $DLMembers.Count +"^"+
          $ACE_DL_HiddenFromAddressListsEnabled +"^"+ $ACE_DL_AcceptMessagesOnlyFrom +"^"+
          $ACE_DL_AcceptMessagesOnlyFromDLMembers
     
          $String | Out-File C:\temp\DLGroup.txt -Append
       }
    }
    
    GetDLStatistics

    Using the <g class="gr_ gr_124 gr-alert gr_spell gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="124" id="124">powershell</g> remoting as per https://blogs.technet.microsoft.com/samdrey/2015/04/06/reminder-adding-exchange-2010-or-2013-snap-in-using-add-pssnapin-not-supported-better-use-remote-powershell-from-rmilne/

    However, I always get this error when I execute it from my laptop PowerShell ISE:

    The pipeline was not run because a pipeline is already running. Pipelines cannot be run concurrently.
       + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
        + FullyQualifiedErrorId : RemotePipelineExecutionFailed
     
    Get-DistributionGroup : The session Session1, c26e3c87-4520-4fae-a161-a2e4e898c74d, PRODHT01-VM is not available to run commands.  The session availability is Busy.
    At C:\Users\Administrator\AppData\Local\Temp\fd154ca6-4cb6-49ed-959f-c256e6a65d34.ps1:9 char:7
    +       $DLData = (Get-DistributionGroup -ErrorAction SilentlyContinue  ...
    +       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: ([PSSession]Session1:PSSession) [Invoke-Command], InvalidRunspaceStateException
        + FullyQualifiedErrorId : InvokeCommandCommandInvalidSessionAvailability,Microsoft.PowerShell.Commands.InvokeCommandCommand
     
    No valid sessions were specified.  Ensure you provide valid sessions that are in the Opened state and are available to run commands.
    At C:\Users\Administrator\AppData\Local\Temp\fd154ca6-4cb6-49ed-959f-c256e6a65d34.ps1:line:9 char:7
    +       $ <<<< DLData = (Get-DistributionGroup -ErrorAction SilentlyContinue -Identity "$_")

    I also tried to execute the same PowerShell command above in the Exchange Server itself but I got this error instead:

    [PRODHT01-VM] Connecting to remote server failed with the following error message : The WinRM client cannot complete the operation within the time specified. Check if the machine name is valid and is reachable over the network and firewall exception for Windows Remote Management service is enabled. For more information, see the about_Remote_Troubleshooting Help topic.
        + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
        + FullyQualifiedErrorId : PSSessionOpenFailed
    Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Supply a non-null argument and try the command again.
    At C:\TEMP\GetDLStats.ps1:2 char:17
    + Import-PSSession <<<<  $Session -AllowClobber
        + CategoryInfo          : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand

    Import-Module : The following error occurred while loading the extended type data file:
    Microsoft.PowerShell, C:\Program Files\Microsoft\Exchange Server\V14\bin\Exchange.partial.Types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".
    Microsoft.PowerShell, C:\Program Files\Microsoft\Exchange Server\V14\bin\exchange.types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".
    Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ActiveDirectory\ActiveDirectory.Types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".

    At C:\TEMP\GetDLStats.ps1:3 char:14
    + Import-Module <<<<  ActiveDirectory -ErrorAction STOP
        + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
        + FullyQualifiedErrorId : FormatXmlUpateException,Microsoft.PowerShell.Commands.ImportModuleCommand

    Creating a new session for implicit remoting of "Get-DistributionGroup" command...
    ForEach-Object : The term 'Get-ADGroupMember' 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.

    At C:\TEMP\GetDLStats.ps1:6 char:107
    +    Get-DistributionGroup -ResultSize Unlimited -ErrorAction SilentlyContinue | ForEach {$_.GUID} | ForEach <<<<  {
        + CategoryInfo          : ObjectNotFound: (Get-ADGroupMember:String) [ForEach-Object], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.ForEachObjectCommand

    Any help would be greatly appreciated.

    Thanks,


    /* Server Support Specialist */

    Thursday, May 19, 2016 1:21 PM

Answers

  • Hi SSS,

    this is due to you exceeding your connection threshold by running parallel queries (pipeline elements run in parallel). Here's a way to run this non-parallel:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRODHT01-VM/PowerShell/ -Authentication Kerberos
    Import-PSSession $Session -AllowClobber
    Import-Module ActiveDirectory -ErrorAction STOP
    
    Function GetDLStatistics
    {
    	$allgroups = Get-DistributionGroup -ResultSize Unlimited -ErrorAction SilentlyContinue
    	foreach ($group in $allgroups)
    	{
    		
    		## Run the Get-DistributionGroup Cmdlet
    		$DLData = $group
    		
    		## Run the Get-QADGroupMember Cmdlet - The @ makes sure it can count 0 and 1 values.
    		$DLMembers = @(Get-ADGroupMember -Identity "$($group.GUID)" -ErrorAction SilentlyContinue)
    		
    		## Get values from Get-DistributionGroup Cmdlet
    		$ACE_DL_Alias = $DLData.Alias
    		$ACE_DL_DisplayName = $DLData.DisplayName
    		$ACE_DL_AcceptMessagesOnlyFrom = $DLData.AcceptMessagesOnlyFrom
    		$ACE_DL_AcceptMessagesOnlyFromDLMembers = $DLData.AcceptMessagesOnlyFromDLMembers
    		$ACE_DL_HiddenFromAddressListsEnabled = $DLData.HiddenFromAddressListsEnabled
    		
    		## Put all values in a string separated by ^ so that it can be put into a CSV.
    		
    		$String = "$($ACE_DL_DisplayName)^$($ACE_DL_Alias)^$($group.GUID)^$($DLMembers.Count)^$($ACE_DL_HiddenFromAddressListsEnabled)^$($ACE_DL_AcceptMessagesOnlyFrom)^$($ACE_DL_AcceptMessagesOnlyFromDLMembers)"
    		
    		$String | Out-File C:\temp\DLGroup.txt -Append
    	}
    }
    
    GetDLStatistics

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Thursday, May 19, 2016 1:41 PM

All replies

  • Exchange version?

    If you're on EX2010, use foreach loops instead of ForEach-Object loops. That's what I usually have to do to get around the concurrent pipe fun.


    EDIT: See Fred's post below.

    Thursday, May 19, 2016 1:41 PM
    Moderator
  • Hi SSS,

    this is due to you exceeding your connection threshold by running parallel queries (pipeline elements run in parallel). Here's a way to run this non-parallel:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRODHT01-VM/PowerShell/ -Authentication Kerberos
    Import-PSSession $Session -AllowClobber
    Import-Module ActiveDirectory -ErrorAction STOP
    
    Function GetDLStatistics
    {
    	$allgroups = Get-DistributionGroup -ResultSize Unlimited -ErrorAction SilentlyContinue
    	foreach ($group in $allgroups)
    	{
    		
    		## Run the Get-DistributionGroup Cmdlet
    		$DLData = $group
    		
    		## Run the Get-QADGroupMember Cmdlet - The @ makes sure it can count 0 and 1 values.
    		$DLMembers = @(Get-ADGroupMember -Identity "$($group.GUID)" -ErrorAction SilentlyContinue)
    		
    		## Get values from Get-DistributionGroup Cmdlet
    		$ACE_DL_Alias = $DLData.Alias
    		$ACE_DL_DisplayName = $DLData.DisplayName
    		$ACE_DL_AcceptMessagesOnlyFrom = $DLData.AcceptMessagesOnlyFrom
    		$ACE_DL_AcceptMessagesOnlyFromDLMembers = $DLData.AcceptMessagesOnlyFromDLMembers
    		$ACE_DL_HiddenFromAddressListsEnabled = $DLData.HiddenFromAddressListsEnabled
    		
    		## Put all values in a string separated by ^ so that it can be put into a CSV.
    		
    		$String = "$($ACE_DL_DisplayName)^$($ACE_DL_Alias)^$($group.GUID)^$($DLMembers.Count)^$($ACE_DL_HiddenFromAddressListsEnabled)^$($ACE_DL_AcceptMessagesOnlyFrom)^$($ACE_DL_AcceptMessagesOnlyFromDLMembers)"
    		
    		$String | Out-File C:\temp\DLGroup.txt -Append
    	}
    }
    
    GetDLStatistics

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Thursday, May 19, 2016 1:41 PM
  • Thanks Fred.

    Yes it works successfully.


    /* Server Support Specialist */

    Thursday, May 19, 2016 11:07 PM
  • Cool, thanks for the tips Mike.

    /* Server Support Specialist */

    Thursday, May 19, 2016 11:08 PM
  • Hi Fred,

    i have the same Problem with this script:

    $AllPublicFolders = Get-publicFolder ‘\UMS’ -recurse

    foreach($Pf in $AllPublicFolders){Get-PublicFolderClientPermission $Pf | Foreach{ Remove-Public
    FolderClientPermission $_.Identity -User Anonymous -AccessRights CreateItems -Confirm:$false}}

    do you have an idea what i can change to make it work?

    regards,

    Daniel


    • Edited by danautomator Wednesday, September 06, 2017 9:33 AM
    Wednesday, September 06, 2017 9:30 AM
  • Hi Daniel,

    this might work (test first!):

    foreach ($Pf in $AllPublicFolders){ Get-PublicFolderClientPermission $Pf | Select -expand Identity | Remove-PublicFolderClientPermission -User Anonymous -AccessRights CreateItems -Confirm:$false }

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Wednesday, September 06, 2017 9:59 AM
  • Thanks Fred.

    i added a 2 second Sleep in the foreach loop and so far this seems to work. on the next couple of folders i'll try your suggestion and let you know.

    regards,

    Daniel

    Wednesday, September 06, 2017 11:54 AM