PowerShell - Setting targetAddress Active Directory attribute for all computers listed in CSV file

Hi,

I would like to add all the individual MAC addresses for each corresponding computer account in Active Directory through PowerShell. The list has already been created in a CSV file.

The column headers in the CSV file are as followed:

sAMAccountName,targetAddress

I checked the info in the CSV file list and the computer names and their corresponding mac addresses are on the same line seperated by a comma, so the CSV file is correct. There are over 100 computers in the list.

I want to write all the MAC addresses to the targetAddress attribute of each of their corresponding computer in AD, but my command is not working.

Here is my command:

Import-Csv c:\updateAD.csv | Set-ADcomputer -Identity { $_.sAMAccountName } -add @{targetAddress = $_.targetAddress}

Can someone help with the syntax, or perhaps I must use a different algorithm ?

Kind Regards,

June 19th, 2013 12:20am

Import-Csv c:\updateAD.csv | foreach { Set-ADcomputer -Identity { $_.sAMAccountName } -add @{targetAddress = $_.targetAddress} }

rgds,

Free Windows Admin Tool Kit Click here and download it now
June 19th, 2013 1:24pm

Import-Csv c:\updateAD.csv | foreach { Set-ADcomputer -Identity { $_.sAMAccountName } -add @{targetAddress = $_.targetAddress} }

rgds,

June 19th, 2013 4:24pm

Import-Csv c:\updateAD.csv | foreach { Set-ADcomputer -Identity { $_.sAMAccountName } -add @{targetAddress = $_.targetAddress} }

rgds,

@ThomRegie: You should also remove the brackets around $_.sAMAccountName. The Identity-parameter needs a string. Wrapping it in brackets suggests script block.
Free Windows Admin Tool Kit Click here and download it now
June 19th, 2013 5:49pm

Are you sure you can set targetAddress using the AD cmdlets? I don't have Exchange in my environment, so I can't test this to be sure, but everything I've read suggests this isn't a good property name to use for storing MAC addresses...
June 20th, 2013 3:12am

Are you sure you can set targetAddress using the AD cmdlets? I don't have Exchange in my environment, so I can't test this to be sure, but everything I've read suggests this isn't a good property name to use for storing MAC addresses...
Free Windows Admin Tool Kit Click here and download it now
June 20th, 2013 6:12am

I agree with Mike Laughlin. I'd be concerned about unintended consequences. If you really want to store this in AD, extend the schema and then use the Set-ADComputer or Set-ADObject command to set the new attribute.

Mike

June 20th, 2013 6:34am

We are going through a GroupWise to Exchange migration and we use the targetAddress on user accounts for forwarding into GroupWise for non migrated users.

I've just tried to pull the targetAddress property for a computer and it doesn't return anything, so doesn't appear that it can be used.

Get-ADComputer computer -properties targetaddress

I've listed all the properties for a computer, and targetaddress is not there.

However, I did have some issues setting the addresses, where the script was reading the hash table incorrectly.

Defining the targetaddress first sorted the problem.

$targetaddress = "smtp:$($_.Alias)@domain" (or in your case $targetaddress = $_.targetaddress)

Set-ADUser $_.UserPrincipalName -Add @{targetaddress=$targetaddress}

Still don't think this will work for computer objects.

It would be nice to have the error message to narrow down the issue.


Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 12:09pm

We are going through a GroupWise to Exchange migration and we use the targetAddress on user accounts for forwarding into GroupWise for non migrated users.

I've just tried to pull the targetAddress property for a computer and it doesn't return anything, so doesn't appear that it can be used.

Get-ADComputer computer -properties targetaddress

I've listed all the properties for a computer, and targetaddress is not there.

However, I did have some issues setting the addresses, where the script was reading the hash table incorrectly.

Defining the targetaddress first sorted the problem.

$targetaddress = "smtp:$($_.Alias)@domain" (or in your case $targetaddress = $_.targetaddress)

Set-ADUser $_.UserPrincipalName -Add @{targetaddress=$targetaddress}

Still don't think this will work for computer objects.

It would be nice to have the error message to narrow down the issue.


  • Edited by Newbie Jones Tuesday, July 02, 2013 4:10 PM added a couple of extra bits of info
July 2nd, 2013 4:08pm

This should be the correct answer.  I was wondering why the initial person was trying to add targetAddress to a computer object, instead of the ADUser object.  This response mentions that, and I believe the format he uses for the set-ADUser command should work.
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 10:31am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics