question

RiccardoChiappini-7815 avatar image
0 Votes"
RiccardoChiappini-7815 asked RichMatheisen-8856 commented

Powershell - import CVS file to fill some attributes in AD

Hello,

i would like to import a .csv file to fill attributes in AD ( for example "ExtensioneAttribute2"); the import match the attribute "mail" for

I try with this two scripts, but without success:

1) Import-Csv c:\user\admin\desktop\test.csv | ForEach-Object {Get-ADUser -filter {mail -eq $.mail}|Set-ADUSer -extensionAttribute2 $.extensionAttribute2}

  • ERROR:

Set-ADUser : A parameter cannot be found that matches parameter name 'extensionAttribute2'.
At line:1 char:118
+ ... ser -filter {mail -eq $.mail}|Set-ADUSer -extensionAttribute2 $.exten ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Set-ADUser : A parameter cannot be found that matches parameter name 'extensionAttribute2'.
At line:1 char:118
+ ... ser -filter {mail -eq $.mail}|Set-ADUSer -extensionAttribute2 $.exten ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser


2) Import-Csv c:\users\chiappini_dlv\desktop\test.csv | ForEach-Object {Set-ADUser $_.mail -ObjectAttributes @{ExtensionAttribute2=($_.ExtensionAttribute2)}} - ERROR: Set-ADUser : A parameter cannot be found that matches parameter name 'ObjectAttributes'. At line:1 char:91 + ... .csv | ForEach-Object {Set-ADUser $_.mail -ObjectAttributes @{Exten ...
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Set-ADUser : A parameter cannot be found that matches parameter name 'ObjectAttributes'.
At line:1 char:91
+ ... .csv | ForEach-Object {Set-ADUser $_.mail ` -ObjectAttributes @{Exten ...
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser




windows-server-powershellwindows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 commented

"extensionAttribute2" is an attribute that's added to your AD schema by the installation of MS Exchange. Are you running an on-premises Exchange organization (or have you extended the AD schema using the Exchange installation media)? Or are you using Microsoft 365?

Assuming you have the Exchange cmdlets available to you, use the Set-MailUser, Set-MailBox, Set-DistributionList, etc. cmdlets (as appropriate) and use the -CustomAttribute2 parameter.

Where did you get the information that states that "-extensionAttribute2" or "-ObjectAttributes" are acceptable parameters for the Set-ADUser cmdlet?

I believe this is what you were trying to accomplish:

 Import-Csv c:\user\admin\desktop\test.csv | 
     ForEach-Object {
         Get-ADUser -filter { mail -eq $._mail } |
                 Set-ADUser -Add @{extensionAttribute2=$_.extensionAttribute2}
     }


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HI Rich,

thank you but still receive error messages. sorry, I forgot to report that I've on-Premises Exchange organization and i can run exchange cmdlet.

In some topic find over the internet, they suggest Set-AdUser but in exchange isn't correct, so I tried with:

Import-Csv c:\users\admin\desktop\test.csv |
ForEach-Object {
Get-mailbox -filter { mail -eq $.mail } |
Set-mailbox -Add @{extensionAttribute2=$
.extensionAttribute2}
}


but i receive this error:


Cannot bind parameter 'Filter' to the target. Exception setting "Filter": ""mail" is not a recognized filterable
property. For a complete list of filterable properties see the command help.
" mail -eq $._mail " at position 2."
At C:\Users\admin\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\srvexch.contoso.local\srvexch.contoso.local.psm1:19836 char:9
+ $steppablePipeline.End()
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.GetMailbox

0 Votes 0 ·
RichMatheisen-8856 avatar image RichMatheisen-8856 RiccardoChiappini-7815 ·

The description of the error is pretty clear. You can't use the property name "mail". Would "EmailAddress" work as well for you?

You switched from Get-ADUser to Get-Mailbox. This is the list of filterable properties for Exchange: filter-properties


0 Votes 0 ·