Do not post any licensing information in this forum.
I know I will win some prize like the newbie of the year but I need again your help. I have a form which will (at least should) be used in place of the now gone Exchange message tracking GUI.
My issue is that when I try to pass arguments to the Get-MessageTrackingLog I get the following error
Get-MessageTrackingLog : A positional parameter cannot be found that accepts argument '-Recipients
At line:75 char:3
+ Get-MessageTrackingLog $argumen1
+ CategoryInfo : InvalidArgument: (:) [Get-MessageTrackingLog], ParameterBindingExcep
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Exchange.Management.TransportL
I have a ttached a demo form so you can have a better idea of what I am doing, the problem seems to arise when I pass the argument to the command from a variable something like this:
[System.String]$argumen1 = "-Recipients "
But if I pass the argument directly as part of the command everything works like this
Get-MessageTrackingLog -Recipients $mbx
My main problem I have multiple textboxes in the form and I build the command depending on what the user has selected so would need a way to pass arguments via variables.
Knowing myself I know I'm overlooking something really stupid but cannot find myself, any pointer?
As usual thanks.
- (18.15 KiB) Downloaded 97 times
Start by reviewing how the CmdLet works. I would also review the basics of how PowerShell CmdLets are designed.
"-Recipients" is a named argument tag. It is NOT an argument. We call the items received be a function or method Parameters. When we send the parameters the values sent are referred to as arguments.
We cannot send the Parameters tag names as string variables. They must be sent as defined.
You will have to build the command up incrementally depending on what you form is intending to do. The easiest way to do this is in the controls validated event. You can use splatting to accomplish this more transparently.
https://technet.microsoft.com/en-us/lib ... 72955.aspx
Now that I am starting to build GUI and somehow adding complexity to my scripts I am realizing how much I still have to learn which is great as keeps motivating me.
Many thanks for the article which I'm going to read and hopefully fix the script.
Until next question
I am sorry that there are no books r foundation articles on using Forms with PowerShell. The C# example code is close but not exact and may be hard to understand if you are not a programmer. You can and should spend time looking at as many good examples of PowerShell scripting as you can find. Read the major blogs. All will become clear in time.
As sometimes life goes I found myself deep into Microosft stuff and some old habits are hard to die, my original question is a good example of this, and not having good foundation on PowerShell and GUI does not help even if C# examples are not taht bad in the end.
Well enough talking have some reading and fixing to do which all good fun for a rainy Friday evening.
Unix arguments/parameters are the same. Actually the structures come from how early C passed arguments to a program and how the early command parsers liked to see the command arguments.
There are ways to stringify a list of arguments and parameter names. THeeasy way is to use a @splat. It can be added to and subtracted from without being concerned about order or nulls.
Who is online
Users browsing this forum: No registered users and 5 guests