Solved

Powershell script request - change DG names and aliases

Posted on 2014-10-20
8
69 Views
Last Modified: 2014-10-20
Looking for a quick PS script to pre-pend all my distribution groups display names and aliases with 'UB_'

Right now I'm going through and manually editing each one, but I've got over 200 of them.
0
Comment
Question by:Ben Hart
  • 4
  • 4
8 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40393083
Get-DistributionGroup -ResultSize Unlimited | % { $nuname = "UB_" + $_ ; Set-DistributionGroup -Identity $_ -Name $nuname -IgnoreNamingPolicy}

Open in new window


Something like above should work.

If you have a list of groups already then you can pipe in from a text file or csv.
0
 
LVL 14

Author Comment

by:Ben Hart
ID: 40393122
so maybe an Import-CSV c:\blah.csv | foreach {set-distributiongroup % { ......
0
 
LVL 14

Author Comment

by:Ben Hart
ID: 40393148
Actually no that doesnt work.  Hmm
0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40393154
Import-Csv blah.csv | %  { $nuname = "UB_" + $_.Name; Set-DistributionGroup -Identity $_.Name -Name $nuname -IgnoreNamingPolicy }

Open in new window


This assumes your csv has a column header named name, eg:

Name
DG1
DG2
DG3
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 14

Author Comment

by:Ben Hart
ID: 40393181
Oh yeah duh.. $_.columnName.

Worked like a champ!

Now is $nuname a specific property field for an object?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40393187
$nuname is the variable we create to hold the value of the new name

$nuname (variable name )

"UB_" + $_.Name; (variable value)

We combine the two strings "UB_" and whatever the value is of the current name to make the new string $nuname which we pass into the command.
0
 
LVL 14

Author Comment

by:Ben Hart
ID: 40393213
Very nice.  Thanks so much!
0
 
LVL 29

Expert Comment

by:becraig
ID: 40393216
No problem, we're here to help.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
A brief introduction to what I consider to be the best editor for PowerShell.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
how to add IIS SMTP to handle application/Scanner relays into office 365.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now