Solved

Powershell script request - change DG names and aliases

Posted on 2014-10-20
8
67 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 28

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 28

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 28

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 28

Expert Comment

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

Featured Post

The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

Join & Write a Comment

Suggested Solutions

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
This video discusses moving either the default database or any database to a new volume.

743 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

10 Experts available now in Live!

Get 1:1 Help Now