Question

I am making an application to collect a lot of exchange data and putting this into a nice interface. so far its working well, however I am running into an issue and I cannot figure it out. I am suspecting it has something to do with the fact that I try to invoke a pipeline within a loop. This is the error I am getting:

A positional parameter cannot be found that accepts argument 'Items'.

and this is my code:

List<Collections.UserMailbox.Accessrights> items = new List<Collections.UserMailbox.Accessrights>();

foreach (string folder in folders)
{
    Pipeline pipe2 = runspace.CreatePipeline();
    pipe2.Commands.Add(new Command("Get-MailboxFolderPermission " + primarysmtpaddress + @":\" + folder ,true"));

    foreach (PSObject psobj in pipe2.Invoke())
    {
        if (!psobj.Properties["AccessRights"].Value.ToString().Equals("None"))
        {
            Collections.UserMailbox.AccessRights item = new Collections.UserMailbox.AccessRights();
            item.AccessRight = psobj.Properties["AccessRights"].Value.ToString();
            item.foldername = psobj.Properties["FolderName"].Value.ToString();
            item.user = psobj.Properties["User"].Value.ToString();
            items.Add(item);
        }
    }
    pipe2.Dispose();
}

public class Collections
{
    public class UserMailbox
    {
        public class AccessRights
        {
            public string accright { get; set; }
            public string foldername { get; set; }
            public string user { get; set; }
        }
    }
}

It errors on the pipe2.invoke() with the error I mentioned above. A previously opened Pipeline I has disposed already.

I hope someone has a solution for me.

Was it helpful?

Solution

I feel so stupid now.. the string folder had "Deleted Items" the command did not have the quotes. so it saw "items" and another parameter to the command. causing the error.... seems so obvious now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top