Reputation: 127
I'm trying to run the powershell script below, but I get:
"Set-ADGroup : A parameter cannot be found that matches parameter name 'mail'.
Script imports a two column csv (left column is group & right column is email address) and then loops through the list setting the mail attribute of each object in the list
Import-CSV -path 'D:\Scripts\AD-AddEmailtoSecGroups\Groups&Emails_Test.csv' | ForEach {get-adgroup -id $_.group | set-adgroup -mail $_.Mail}
Upvotes: 1
Views: 10690
Reputation: 2676
Try this.
Import-CSV -path 'D:\Scripts\AD-AddEmailtoSecGroups\Groups&Emails_Test.csv' | ForEach-Object {Set-ADGroup -Identity $_.group -Replace @{mail="$_.email"}}
EDIT: I think I assumed the email property would be called 'email' in your csv. I just see that you are using 'mail' instead. So minor change:
Import-CSV -path 'D:\Scripts\AD-AddEmailtoSecGroups\Groups&Emails_Test.csv' | ForEach-Object {Set-ADGroup -Identity $_.group -Replace @{mail="$($_.mail)"}}
Upvotes: 2
Reputation: 536
You need to use the -Replace
parameter to access the mail property as it doesn't have its own parameter in Set-ADGroup
. When passing the hash to the -Replace
parameter, you also just need to make sure you're accessing the 'mail' property in your object you're passing over to the command appropriately.
This should do the trick:
Import-CSV -path 'D:\Scripts\AD-AddEmailtoSecGroups\Groups&Emails_Test.csv' |
ForEach-Object {Set-ADGroup -Identity $_.group -Replace @{mail="$($_.mail)"}}
Upvotes: 1