codectified
codectified

Reputation: 1

set ad user title to group name

I want to set the title of all users in a set of groups to the names of said groups. All of the groups begin with "Position - " in the name.

Here is an example of what I know I can do manually for each group:

get-adgroupmember -identity "Position - Accounts Payable Specialist" | get-aduser -properties title | % {set-aduser $_ -title "Accounts Payable Specialist"}

As you can tell, I'm manually removing the beginning "Position - " part of the group name, so if anyone knows of way to do this simultaneously or after the fact as well, I would appreciate it!

Upvotes: 0

Views: 273

Answers (1)

jimbobmcgee
jimbobmcgee

Reputation: 1721

Something like...

Get-ADGroup -Filter 'Name -like "Position - *"' | %{
    $g = $_
    $jobTitle = $g.Name.Substring(0, 11).Trim()

    Get-ADGroupMember -Identity $g | Get-ADUser -Properties Title | %{
        Set-ADUser $_ -Title $jobTitle -WhatIf
    }
}

You don't technically need to assign $g = $_ in this case, but it might help to differentiate once you nest the ForEach-Object call.

Upvotes: 1

Related Questions