0

The following PowerShell script attempts to create an Exchange mailbox for a user with (a) a retention policy and (b) an archive quota:

PSCommand command = new PSCommand();

command.AddCommand("Enable-Mailbox");
command.AddParameter("Alias", K2.ProcessInstance.DataFields["Account-ADAlias"].Value.ToString());
command.AddParameter("Identity", K2.ProcessInstance.DataFields["Account-ADAlias"].Value.ToString());
command.AddParameter("Database", K2.ProcessInstance.DataFields["Account-MailboxDatabase"].Value.ToString());

command.AddCommand("Enable-Mailbox");
command.AddParameter("Identity", K2.ProcessInstance.DataFields["Account-ADAlias"].Value.ToString());
command.AddParameter("Archive");

command.AddCommand("Set-Mailbox");
command.AddParameter("Identity", K2.ProcessInstance.DataFields["Account-ADAlias"].Value.ToString());
command.AddParameter("Database", K2.ProcessInstance.DataFields["Account-MailboxDatabase"].Value.ToString());
command.AddParameter("ArchiveQuota", "2GB");
command.AddParameter("ArchiveWarningQuota", "1.8GB");
command.AddParameter("RetentionPolicy", "No Archive Delete after 10years");

powershell.Commands = command;

The following error is generated when the script is run:

Parameter set cannot be resolved using the specified named parameters.

NOTE: The variables staring with "K2.ProcessInstance.Datafields" have all been verified as valid.

I can't figure out how to resolve this error. I've consulted the PowerShell module docs for Exchange. Any guidance appreciated.

Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
PhillyD
  • 181
  • 1
  • 18
  • Was a line number given or code snippet quoted in the error message, which you can share with us? If you provide the line number, let us know what line that matches up with. – Adam Feb 25 '20 at 16:49
  • This app uses a workflow server which runs this code, I am trying to get the error log files so I can see the error in more detail – PhillyD Feb 25 '20 at 16:50

1 Answers1

1

Powershell can't figure out which parameter-set you're employing with this specific call.

Enable-Mailbox employs several different parameters-sets. I think there are 13 different parameter-sets the commandlet accepts. By only supplying Alias, Identity, and Database, Powershell can't figure out which parameter-set is being employed so it throws up its hands and gives you that error. This is because those three params are a part of almost every parameter-set in the list (I think Database is omitted from one).

The problem was described (for a different use-case) in the the post PowerShell unable the determine which Parameter Set is in use

Hope this helps!

A-

Adam
  • 3,891
  • 3
  • 19
  • 42