Link to home
Start Free TrialLog in
Avatar of sirichaiphumirat
sirichaiphumiratFlag for United States of America

asked on

Exchange 2010 Powershell Script to create distribution list

Hello Totally New at the scripting.  But i'm trying to make a script so our help desk can create distro group with emails without having to connect to the exchange server it self, and only having them use a powershell script. Below is the script that i came up with, but having a bit of an issue trying to get it to work. As i am not sure how i can get  return the switch result in to a variable.  

This is exchange 2010.  Thanks for helping out in advance.



$DistributionGoup = Read-Host -Prompt 'New Distribution Group Name ( No Spaces)'
$Alias = Read-Host -Prompt 'Enter Alias Name'

Write-Host Please Pick The Domain From The Following List
Write-Host 1. CB Domain
Write-Host 2. TB Domain
Write-Host 3. PS Domain
Write-Host 4. GB Domain
Write-Host 5. TC Domain

$domain = Read-Host -Prompt "Domain"

switch ($domain)
{
1 {"cb.smbmi.local/distribution Groups";break}
2 {"tb.smbmi.local/distribution Lists";break}
3 {"ps.smbmi.local/distribution Groups";break}
4 {"gb.smbmi.local/distribution Groups";break}
5 {"tc.smbmi.local/distribution Groups";break}
default {"No Domain Determined."}

}


new-DistributionGroup -Name $DistributionGoup  -OrganizationalUnit $domain -SamAccountName $DistributionGoup -Alias $DistributionGoup
ASKER CERTIFIED SOLUTION
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sirichaiphumirat

ASKER

Great thank you.
Sorry quick question, how can i add spaces within the variable.   For the example above.  distribution groups  has a space in them.
Enclose the name in double quotes
Eg.   "Group name with space"
Thanks