mobot
asked on
Importing ExtensionAttribute into AD user accounts
I am running the following script:
Import-Csv C:\scripts\import\adimport 041317.csv |ForEach-Object {
Set-ADUser $_.samAccountName -Replace @{
ExtensionAttribute1=$_.Ext ensionAttr ibute1
ExtensionAttribute2=$_.Ext ensionAttr ibute2
ExtensionAttribute3=$_.Ext ensionAttr ibute3
ExtensionAttribute4=$_.Ext ensionAttr ibute4
ExtensionAttribute5=$_.Ext ensionAttr ibute5
}
}
I receive the following error:
Set-ADUser : replace
At C:\scripts\import\UpdateAD Script.ps1 :2 char:5
+ Set-ADUser $_.samAccountName -Replace @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~
+ CategoryInfo : InvalidOperation: (******:ADUser) [Set-ADUser], ADInvalidOperationExceptio n
+ FullyQualifiedErrorId : replace,Microsoft.ActiveDi rectory.Ma nagement.C ommands.Se tADUser
Set-ADUser : Cannot find an object with identity: '' under: 'DC=*****,DC=org'.
I know I am missing something with this script
Import-Csv C:\scripts\import\adimport
Set-ADUser $_.samAccountName -Replace @{
ExtensionAttribute1=$_.Ext
ExtensionAttribute2=$_.Ext
ExtensionAttribute3=$_.Ext
ExtensionAttribute4=$_.Ext
ExtensionAttribute5=$_.Ext
}
}
I receive the following error:
Set-ADUser : replace
At C:\scripts\import\UpdateAD
+ Set-ADUser $_.samAccountName -Replace @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (******:ADUser) [Set-ADUser], ADInvalidOperationExceptio
+ FullyQualifiedErrorId : replace,Microsoft.ActiveDi
Set-ADUser : Cannot find an object with identity: '' under: 'DC=*****,DC=org'.
I know I am missing something with this script
ASKER
At line:9 char:8
+ catch { write-error $error[0].exception.messag e }
+ ~
Missing '=' operator after key in hash literal.
At line:12 char:5
+ }
+ ~
The Try statement is missing its Catch or Finally block.
At line:1 char:100
+ ... ame -ne $null) {
+ ~
Missing closing '}' in statement block.
At line:1 char:65
+ Import-Csv C:\scripts\import\adimport 041317.csv |ForEach-Object { If ($_.samAcco ...
+ ~
Missing closing '}' in statement block.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordE xception
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral
+ catch { write-error $error[0].exception.messag
+ ~
Missing '=' operator after key in hash literal.
At line:12 char:5
+ }
+ ~
The Try statement is missing its Catch or Finally block.
At line:1 char:100
+ ... ame -ne $null) {
+ ~
Missing closing '}' in statement block.
At line:1 char:65
+ Import-Csv C:\scripts\import\adimport
+ ~
Missing closing '}' in statement block.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordE
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral
Ugh - have to learn to paste into ise first...oops. :^)
Import-Csv C:\scripts\import\adimport041317.csv | `
ForEach-Object {
If ($_.samAccountName -ne $null) {
try {
Set-ADUser $_.samAccountName -Replace @{
ExtensionAttribute1=$_.ExtensionAttribute1
ExtensionAttribute2=$_.ExtensionAttribute2
ExtensionAttribute3=$_.ExtensionAttribute3
ExtensionAttribute4=$_.ExtensionAttribute4
ExtensionAttribute5=$_.ExtensionAttribute5
} #end set-aduser
} catch {
write-error $error[0].exception.message }
} # end try/catch
} #end foreach-object
ASKER
Now I see this:
replace
At line:2 char:16
+ ForEach-Object {
+ ~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Comma nds.WriteE rrorExcept ion
replace
At line:2 char:16
+ ForEach-Object {
+ ~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Comma
ASKER
OK, I discover that if a field is blank in my csv my script would not run. So how can I run it with mutliple accounts and possible blank fields
This works for me but it is one record with one attribute
Import-Csv C:\scripts\import\adimport 041317.csv |ForEach-Object {
Set-ADUser $_.samAccountName -Replace @{ExtensionAttribute4=$_.E xtensionAt tribute4}}
This works for me but it is one record with one attribute
Import-Csv C:\scripts\import\adimport
Set-ADUser $_.samAccountName -Replace @{ExtensionAttribute4=$_.E
ASKER
Now my entire script is working as long as I do not include attributes that could be blank, How do I get around that issue, if it is null?
Import-Csv C:\scripts\import\adimport 041317.csv |ForEach-Object {
Set-ADUser $_.samAccountName -Replace @{
ExtensionAttribute1=$_.Ext ensionAttr ibute1
ExtensionAttribute2=$_.Ext ensionAttr ibute2
ExtensionAttribute4=$_.Ext ensionAttr ibute4
}
}
Import-Csv C:\scripts\import\adimport
Set-ADUser $_.samAccountName -Replace @{
ExtensionAttribute1=$_.Ext
ExtensionAttribute2=$_.Ext
ExtensionAttribute4=$_.Ext
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It's the weirdest thing, it keeps hanging on the EstensionAtribute3 because it is blank but if I put a variable in it; it runs without any errors.
Set-ADUser : replace
At line:13 char:3
+ Set-ADUser $_.samAccountName -Replace @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~
+ CategoryInfo : InvalidOperation: (PRaven:ADUser) [Set-ADUser], ADInvalidOperationExceptio n
+ FullyQualifiedErrorId : replace,Microsoft.ActiveDi rectory.Ma nagement.C ommands.Se tADUser
Set-ADUser : replace
At line:13 char:3
+ Set-ADUser $_.samAccountName -Replace @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (PRaven:ADUser) [Set-ADUser], ADInvalidOperationExceptio
+ FullyQualifiedErrorId : replace,Microsoft.ActiveDi
ASKER
Thank you so much. I will run the scrip with out blank data. Not sure why it is still not working but you have been an awesome help. Have a Happy Eater.
Hi Moto,
Since we check if it is NULL the item that was tripping it up likely had some sort of whitespace character in it which AD would not accept, perhaps a "TAB" character.
Thanks for the points and happy easter.
Ben
Since we check if it is NULL the item that was tripping it up likely had some sort of whitespace character in it which AD would not accept, perhaps a "TAB" character.
Thanks for the points and happy easter.
Ben
Open in new window