Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:56:18+00:00 2026-06-13T12:56:18+00:00

In PowerShell (PS), is it important to use cmdlet parameters in the order in

  • 0

In PowerShell (PS), is it important to use cmdlet parameters in the order in which they’re defined in the official syntax?

I’m adding the -cc parameter to send-mailMessage in an existing script. I added -cc immediately after -To and it works just fine, so I’m inclined to leave well enough alone. But the cmdlet’s only parameter set is defined as follows in the help text:

Send-MailMessage [-To] <String[]> [-Subject] <String> [[-Body] <String> ] [[-SmtpServer] <String> ] -From <String> [-Attachments <String[]> ] [-Bcc <String[]> ] [-BodyAsHtml] [-Cc <String[]> ] [-Credential <PSCredential> ] [-DeliveryNotificationOption <DeliveryNotificationOptions> ] [-Encoding <Encoding> ] [-Port <Int32> ] [-Priority <MailPriority> ] [-UseSsl] [ <CommonParameters>]

So I assume best practice would be to run a command like this (cc after subject, body, smtpserver, and from, following the help text):

send-mailmessage -to $mailTo -subject $mailSubj -body $msgbody -smtpserver smtp.domain.tld -from $mailFrom -cc $mailCC

…instead of like this (cc before many of those other parameters):

send-mailmessage -to $mailTo -cc $mailCC -subject $mailSubj -body $msgbody -smtpserver smtp.domain.tld -from $mailFrom

In general I haven’t been super careful about this, and stuff works. So surely it’d be overkill (not to mention error-prone) to go back and adjust functional existing scripts along these lines. But maybe it’s worth respecting the parameter order going forward, in future scripts? Or not worth the trouble? What say you?

Of course you don’t want to make a bad assumption about which parameter is the default and then omit the parameter name; I can also imagine this sort of thing getting messy with custom functions or etc. But my question is about the simpler case, when the parameters of an in-the-box cmdlet are explicitly named, as with the send-mailMessage examples above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:56:19+00:00Added an answer on June 13, 2026 at 12:56 pm

    If you are naming your parameters when invoking a cmdlet (e.g.Get-ChildItem -Path *.txt) then it doesn’t matter what order you specify them in. Everything is exactly specified by name, so the order in which params were provided is not needed to resolve the arguments.

    If you are NOT naming your parameters (e.g. Get-ChildItem *.txt) then it does matter. The cmdlet author can specify that certain parameters can/should be expected, without names, in a certain order. The Powershell engine will try its best to honor that, and in general it will try to pair un-named arguments to any parameters which have not yet been assigned.

    Check out this page on parameter types for some more technical info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Powershell provides the New-WebServiceProxy cmdlet which allows for a web service proxy object to
In PowerShell you can use the Get-WmiObject cmdlet to grab WMI classes. I have
In PowerShell 1.0, if I have a cmdlet parameter of an enum type, what
On episode #162 of Hanselminutes they were talking about PowerShell, but more importantly around
In PowerShell, syntax for if is as so: if (<test1>) {<statement list 1>} [elseif
In PowerShell you can use pushd (an alias for Push-Location ) and popd (an
My powershell script takes the following parameter: Param($BackedUpFilePath) The value that is getting passed
In PowerShell you can use [xml] to mean [System.Xml.XmlDocument]. Do you know where I
Using powershell, you can use the '&' character to run another application and pass
I'm new to PowerShell, but I would like to use it, because there isn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.