• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 78
  • Last Modified:

Powershell script request - change DG names and aliases

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
Ben Hart
Asked:
Ben Hart
  • 4
  • 4
1 Solution
 
becraigCommented:
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
 
Ben HartAuthor Commented:
so maybe an Import-CSV c:\blah.csv | foreach {set-distributiongroup % { ......
0
 
Ben HartAuthor Commented:
Actually no that doesnt work.  Hmm
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
becraigCommented:
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
 
Ben HartAuthor Commented:
Oh yeah duh.. $_.columnName.

Worked like a champ!

Now is $nuname a specific property field for an object?
0
 
becraigCommented:
$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
 
Ben HartAuthor Commented:
Very nice.  Thanks so much!
0
 
becraigCommented:
No problem, we're here to help.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now