it-capitain
Goto Top

Custom Attributes im AD via PowerShell (CSV) füllen

Hallo zusammen,

ich habe im Active Directory insgesamt 3 zusätzliche Benutzer Attribute erstellt:

Attr1
Attr2
Attr3

Diese möchte ich jetzt befüllen. Dazu habe ich ein bestehendes PowerShell Script einfach erweitert, allerdings ohne Erfolg.

$path = "Import.csv"   
$csv  = Import-Csv $path -Delimiter ';'  
Import-Module ActiveDirectory

foreach ($line in $csv)
{
  $user     = Get-Aduser -Filter "sAMAccountName -eq '$($line.sAMAccountName)'"  
  $array    = @()
  $hash     = $null
  
  $array    = New-Object PSObject -Property @{   
    givenName = $line.givenName
    sn  = $line.sn
    attr1 = $line.attr1
    attr2 = $line.attr2
    attr3 = $line.attr3
    streetaddress = $line.streetaddress
    postalCode = $line.postalCode
    l = $line.l
      }
    
  foreach ($arr in $array)
  {
    $arr.PsObject.Properties | ?{ ($_.Value) } | %{
      $hash += @{
        ($_.Name) = ($_.Value)
      }
    }
  }

  Set-ADUser $user -Replace $hash
  
}

Die CSV sieht wie folgt aus:
sAMAccountName;givenName;sn;attr1;attr2;attr3;streetaddress;postalCode;l
MaxMust;Max;Muster;;Herr;männlich;Musterweg 40;12345;Hamburg

Kann mir einer einen Tipp geben, wieso das ganze soweit klappt, außer bei den Custom Attributes? Bin absolut kein Profi im "Scripten" und bin schon froh, dass ich das soweit hinbekommen habe, aber hier benötige ich Hilfe.

Danke schon einmal für jeden Tipp.

Grüße,
Olli

Content-Key: 665312

Url: https://administrator.de/contentid/665312

Printed on: April 25, 2024 at 01:04 o'clock

Member: IT-Pro
IT-Pro Apr 01, 2021 updated at 07:59:13 (UTC)
Goto Top
Hi,

Sehr ähnlicher Beitrag, hier auf administrator.de, auch erst vor wenigen Tagen entstanden...
AD User Import CSV
Member: IT-Capitain
IT-Capitain Apr 01, 2021 at 07:35:21 (UTC)
Goto Top
Ok, und wo?
Member: IT-Pro
IT-Pro Apr 01, 2021 at 07:56:56 (UTC)
Goto Top
Ich habe doch direkt darunter einen Beitrag verlinkt?
Member: IT-Capitain
IT-Capitain Apr 01, 2021 at 10:45:10 (UTC)
Goto Top
Danke, jetzt geht der auch bei mir. Ich schau mal
Member: IT-Capitain
IT-Capitain Apr 01, 2021 at 11:16:44 (UTC)
Goto Top
So bin damit mal durch, aber leider nur sehr ähnlich und es wird nicht auf Custom Attributes eingegangen, die man manuell dem AD hinzugefügt hat.
Member: em-pie
em-pie Apr 02, 2021 at 16:48:01 (UTC)
Goto Top
Moin,

probiere es einfach mal mit
extensionAttribute1  = $line.attr1 
extensionAttribute2  = $line.attr2
extensionAttribute3  = $line.attr3

denn so lauten die Felder im AD-Objekt tatsächlich.
Mach mal in einer Console folgendes:
Get-ADUser -Identity IT-Capitain -Properties *

Gruß
em-pie