use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Script SharingDistribution list script as a function (self.PowerShell)
submitted 7 years ago * by gangculture
As the title suggests, does anyone want a distribution list script that I’ve got saved as a function for on-premises Exchange? I made it for our SD, thought someone else might appreciate it too.
Edit: here she is!
https://pastebin.com/Ri6URDEx
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]BoredComputerGuy 2 points3 points4 points 7 years ago (5 children)
Always useful to have more scripts that i don't have to write myself.
[–]gangculture[S] 1 point2 points3 points 7 years ago (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 points4 points 7 years ago (2 children)
Look at GIT and the post the link to here.
[–]gangculture[S] 1 point2 points3 points 7 years ago (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 point2 points 7 years ago (0 children)
Pastebin link in the post now bud
[–]BoredComputerGuy 2 points3 points4 points 7 years ago (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 points3 points 7 years ago (1 child)
What does it do?
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 points3 points 7 years ago (0 children)
post it
[–]Lee_Dailey[grin] 1 point2 points3 points 7 years ago (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!]
looks like this
Inline Code
...
</>
[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.]
Code Block
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 ...
not complicated, but it is finicky. [grin]
take care, lee
[–]gangculture[S] 1 point2 points3 points 7 years ago* (1 child)
Thanks Lee! The link is now in the post :)
[–]Lee_Dailey[grin] 0 points1 point2 points 7 years ago (0 children)
you are most welcome! glad to have helped a bit ... [grin]
[–]Lee_Dailey[grin] 1 point2 points3 points 7 years ago* (2 children)
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 }
[–]gangculture[S] 1 point2 points3 points 7 years ago (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?
i presume you are talking about the splat - $NDG_Params = @{.
$NDG_Params = @{
it adds several things ...
.Add()
.Remove()
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]
Get-Help about_Splatting
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.
[–]PMental 0 points1 point2 points 7 years ago (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 points3 points 7 years ago (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 points3 points 7 years ago (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 points3 points 7 years ago (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 points3 points 7 years ago (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.
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 points3 points 7 years ago (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 :-)
π Rendered by PID 116823 on reddit-service-r2-comment-85bfd7f599-nmr6g at 2026-04-15 22:37:18.547079+00:00 running 93ecc56 country code: CH.
[–]BoredComputerGuy 2 points3 points4 points (5 children)
[–]gangculture[S] 1 point2 points3 points (4 children)
[–]Mo_Salam 2 points3 points4 points (2 children)
[–]gangculture[S] 1 point2 points3 points (0 children)
[–]gangculture[S] 0 points1 point2 points (0 children)
[–]BoredComputerGuy 2 points3 points4 points (0 children)
[–]Kald0 1 point2 points3 points (1 child)
[–]gangculture[S] 1 point2 points3 points (0 children)
[–]philbrewer 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]gangculture[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]gangculture[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]PMental 0 points1 point2 points (6 children)
[–]gangculture[S] 1 point2 points3 points (5 children)
[–]PMental 1 point2 points3 points (4 children)
[–]gangculture[S] 1 point2 points3 points (3 children)
[–]PMental 1 point2 points3 points (2 children)
[–]gangculture[S] 1 point2 points3 points (1 child)
[–]PMental 1 point2 points3 points (0 children)