getting ForEach-Object : Parameter set cannot be resolved using the specified named parameters.

Pratiksha Vaidya 6 Reputation points
2021-05-21T13:15:23.14+00:00

Hi,

Using powershell script and EWS API I am trying to login to two mailboxes. Deleting mails in it. and send mails to two mailboxes(each other).

I am putting all the code inside parallel block.

I am getting error as:
ForEach-Object : Parameter set cannot be resolved using the specified named parameters.
At C:\Documents\test\File.ps1:29 char:15

  • $collection | ForEach-Object -Parallel {
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : MetadataError: (:) [ForEach-Object], ParameterBindingException
  • FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.ForEachObjectCommand

I get above error on running in run mode in vs code.
But when I debug the code its getting executed and giving error at delete mail authentication part as:
Autodiscover() service can't be located.

also one more thing when I run code in run mode its terminating but when debugging using breakpoints it is printing write-host statements. Why is it so.

Please help me out for both questions.

Thanks in advance.

Pratiksha

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2021-05-24T04:43:10.627+00:00

    Hi,

    The "-parallel" parameter was introduced in PowerShell 7. What is the version of your PowerShell? You can check it with $PSVersionTable.

    Best Regards,
    Ian Xue

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

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.
    0 comments No comments

  2. Pratiksha Vaidya 6 Reputation points
    2021-05-24T12:05:38.963+00:00

    Hi,

    Thanks for your reply.
    I am using powershell 7.1.3 version
    I checked by debugging what happening is, it is getting terminated at parallel block statement and printing message from catch block.
    Please suggest further.
    Also suggest, why it is happening like, I am not able to see anything except printed error message when I am simply running it but in debugging I am able to see control passed to functions.

    Thanks in advance.

    Pratiksha.

    1 person found this answer helpful.

  3. Pratiksha Vaidya 6 Reputation points
    2021-05-28T12:01:40.103+00:00

    Thanks for your reply.
    Let me tell you what exactly I want to perform.

    I will execute .bat file in which I will mention xml,ps1,log file paths.
    Program is divided into 3 parts: pre-processing ,main(),post processing
    I want to login to multiple tenant mail boxes delete there previous mail, send mail and receive mail reception. In getcred() I am encrpting password using converttosecurestring commandlet.
    I want to execute this using powershell 7 and EWS API.

    Please tell me should I need to change script function sequence or what.
    Out of all this functionality which code should be there inside parallel block.

    Please find below error msg:
    C:\Projects\Code Files_Parallel_Processing for multiple tenants>set PS1='C:\Projects\Code Files_Parallel_Processing for multiple tenants\File.ps1'

    C:\Projects\Code Files_Parallel_Processing for multiple tenants>set LOG='C:\Projects\Code Files_Parallel_Processing for multiple tenants\POC-DeleteChange.log'

    C:\Projects\Code Files_Parallel_Processing for multiple tenants>set XML='C:\Projects\Code Files_Parallel_Processing for multiple tenants\POC.xml'

    C:\Projects\Code Files_Parallel_Processing for multiple tenants>cd /d C:\Projects\Code Files_Parallel_Processing for multiple tenants\

    C:\Projects\Code Files_Parallel_Processing for multiple tenants>Powershell.exe -command "&{&'C:\Projects\Code Files_Parallel_Processing for multiple tenants\testforsp.ps1' 'C:\Projects\Code Files_Parallel_Processing for multiple tenants\POC-DeleteChange.log' 'C:\Projects\Code Files_Parallel_Processing for multiple tenants\POC.xml';exit $LASTEXITCODE}"
    INFO001 [Started email sending / receiving normality monitoring tool.] Log file:C:\Projects\Code Files_Parallel_Processing for multiple tenants\POC-DeleteChange.log, Configuration file:C:\
    Projects\Code Files_Parallel_Processing for multiple tenants\POC.xml
    INFO002 Pre-process.
    INFO 003 Load the configuration file.
    Tenant Details - pv1@Stuff .com C:\Projects\Code Files_Parallel_Processing for multiple tenants\EncryptedPassWord.txt
    Tenant Details - pv2@Stuff .com C:\Projects\Code Files_Parallel_Processing for multiple tenants\EncryptedPassWord2.txt
    INFO004 Starts the main process.


    ErrorLog =>Parameter set cannot be resolved using the specified named parameters.


    ERROR032 The main process could not continue because an error occurred in the main process.
    ERROR032 The main process could not continue because an error occurred in the main process.
    PS C:\Projects\Code Files_Parallel_Processing for multiple tenants>

    Script execution flow is as follows:

    1. Adding xml,ps1,log file path in .bat file
    2. running .bat file in terminal
    3. File.ps1 structure:

    reading xml,log file

    variable declaration

    initial processing function

    init()
    {
    checkxml()
    getxml()
    }
    main()
    {
    try{
    $collection = foreach ($tenantDetails in $script:gXMLINFO.tenants.tenant) {
    $out = [ordered]@{
    tid = $tenantDetails.id
    tmailbox = $tenantDetails.box
    tpass = $tenantDetails.password
    }
    [pscustomobject]$out
    }
    $collection | ForEach-Object -Parallel {
    getcred() #require to login to mailbox
    deletemail()
    sendmail()
    receive()

    Actual lines where getting cred,delete,send mail works

    foreach ($tenantDetails in $script:gXMLINFO.tenants.tenant) {
    if ( (GetCredential) -eq $false) {
    return $false
    }

              if ( (SendMailMessage $script:gLOGINID) -eq $false) {  
                return $false  
            }  
        }  
    

    }##parallel block close
    }##main close

    trigger point of script

    initialize()
    main()

    post processing

    printing error logs

    Please Please help me out.
    Thanks in advance.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.