Solved

Powershell script request - change DG names and aliases

Posted on 2014-10-20
8
70 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
Read this checklist to learn more about the 15 things you should never include in an email signature.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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