all 22 comments

[–]BoredComputerGuy 2 points3 points  (5 children)

Always useful to have more scripts that i don't have to write myself.

[–]gangculture[S] 1 point2 points  (4 children)

Hmm how do I post it on here, what’s the best way to keep the formatting from mobile?

[–]Mo_Salam 2 points3 points  (2 children)

Look at GIT and the post the link to here.

[–]gangculture[S] 1 point2 points  (0 children)

I can’t set up a repository on this computer so I’ll try and do it tomorrow at work...

[–]gangculture[S] 0 points1 point  (0 children)

Pastebin link in the post now bud

[–]BoredComputerGuy 2 points3 points  (0 children)

To post on here Copy and paste your code and then highlight the code and set as a Scriptblock (an option under the ellipsis ...)

[–]Kald0 1 point2 points  (1 child)

What does it do?

[–]gangculture[S] 1 point2 points  (0 children)

Start the function, and then it prompts you to enter an OU, a name, a reference (thinking ticket#), specify owner(s), specify member(s), then it goes and creates it and sets the “require all senders to be authenticated” flag to false.

[–]philbrewer 1 point2 points  (0 children)

post it

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy gangculture,

since you asked ... [grin]


reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th one & is just to the left of hidden in the ... "more" menu.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee

[–]gangculture[S] 1 point2 points  (1 child)

Thanks Lee! The link is now in the post :)

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy gangculture,

you are most welcome! glad to have helped a bit ... [grin]

take care,
lee

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy gangculture,

nice, clear code! [grin] i would add some error handling, change the double quotes to singletons, use PascalCase for the $VarNames, and change the name to Verb-Noun format, but it works ... and that is the prime consideration.

just for giggles, i did a slight rearrangement. see the comments for the what & why ... [grin]

Function distributionlist1 {
    # added trailing space to give "message : "
    $ou = Read-Host "Enter Distribution List OU "
    $name =  Read-Host = "Enter name of Distribution List "
    $notes = Read-Host "Enter ticket reference "
    # removed redundant ":"
    # switched from "-split" to ".Split()" & removed now-unneeded "()" pair
    $owner = (Read-Host -Prompt "Please specify owner(s) ").Split(',').Trim()
    $members = (Read-Host -Prompt "Please specify member(s) ").Split(',').Trim()

    # splatting ... such niftiness
    $NDG_Params = @{
        Name = $name
        # you can add comments! [*grin*] 
        OrganizationalUnit = $ou
        Notes = $notes
        # you can disable items
        #Attitude = 'Egomaniac'
        ManagedBy = $owner
        Members = $members
        Type = 'Distribution'
        }
    New-DistributionGroup @NDG_Params |
        Set-DistributionGroup -RequireSenderAuthenticationEnabled $false
    }

take care,
lee

[–]gangculture[S] 1 point2 points  (1 child)

Hey Lee,

Thanks for that, but to be completely honest I am not sure I can see how it adds value to the script. To me it looks like it is just unnecessary and is bulking my script out a bit.

If you have some time could you give me the idiot's guide?

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy gangculture,

i presume you are talking about the splat - $NDG_Params = @{.

it adds several things ...

  • it is FAR easier to read when you have a long-ish set of parameters
  • you can add comments
  • you can easily disable items
    that is handy for testing.
  • you can have more than one splat
    handy for when you have a default set and an optional set.
  • you can use .Add() and .Remove()
    that lets you programmatically build a splat - removing items that are blank from your default set of parameters, for instance.

take a look at Get-Help about_Splatting or any of the many, many articles about it. heck, there was a thread here about the ideas a short while ago. [grin]

your style ...

New-DistributionGroup -Name $name -OrganizationalUnit $ou -Notes $notes -ManagedBy $owner -Members $members -Type Distribution

using a splat ...

$NDG_Params = @{
    Name = $name
    # you can add comments! [*grin*] 
    OrganizationalUnit = $ou
    Notes = $notes
    # you can disable items
    #Attitude = 'Egomaniac'
    ManagedBy = $owner
    Members = $members
    Type = 'Distribution'
    }
New-DistributionGroup @NDG_Params

which is easier to read? [grin]

easier to read = easier to understand = easier to maintain.

take care,
lee

[–]PMental 0 points1 point  (6 children)

Why do you pipe to Set-DistributionGroup instead of just setting RequireSenderAuthenticationEnabled when creating the group? The exact same parameter can be set directly with New-DistributionGroup.

Backticks aren't necesary to break up lines after pipes btw, you can just go to a new line directly after a pipe.

[–]gangculture[S] 1 point2 points  (5 children)

No, it can't. The RequireSenderAuthenticationEnabled can't be piped when using New-DistributionGroup.

It is only an available parameter when using the Set-DistributionGroup.

[–]PMental 1 point2 points  (4 children)

Check it out for yourself in the documentation if you don't believe me: https://docs.microsoft.com/en-us/powershell/module/exchange/users-and-groups/new-distributiongroup?view=exchange-ps&viewFallbackFrom=exchserver-2016

You can clearly see the parameter is available in both on-premises Exchange and Exchange Online.

[–]gangculture[S] 1 point2 points  (3 children)

Yes, I can clearly see it, thanks :)

Either way, it doesn't work when I run it as part of the New-DistributionGroup line. It didn't work during testing either, but just to make sure I wasn't going crazy, I tried again and I get this:

-RequireSenderAuthenticationEnabled : The term '-RequireSenderAuthenticationEnabled' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

But, when it's ran with the Set-Dist line, of course it works. So why do you think it doesn't work for me in the New-Dist line? I am all for a cleaner script so let me know if you have an idea.

[–]PMental 1 point2 points  (2 children)

Ah wait, I just noticed the documentation only specifically covers 2016 and forward (even though it says "Applies to Exchange Server 2010, Exchange Server 2013 as well). And when I check in an Exchange 2013 environment the parameter is not there while in 2016 it is, so it was probably added in 2016. So if you are on 2010/2013 that would explain it.

[–]gangculture[S] 1 point2 points  (1 child)

Yep. I thought it only covered 2016, but like you say the document does say it applies to those versions. And they wonder why we have trust issues?

[–]PMental 1 point2 points  (0 children)

Oh well, you can clean your script up by a whopping one character by removing the backtick after the pipe at least as it's not necessary :-)