Ga naar inhoud

jonathanb

Lid
  • Items

    1
  • Registratiedatum

  • Laatst bezocht

Berichten die geplaatst zijn door jonathanb

  1. Hallo allemaal,

    Ik heb een Powershell script die telkens een foutmelding geeft als ik een gebruiker wil aanpassen. Het maken van de gebruiker gaat geweldig en de gegevens komen van een CSV bestand.

    Dit is wat ik nu heb:

    $connection = [ADSI] "LDAP://localhost:389/ou=Test,dc=oxl,dc=local"
    # Connectie met de AD
    
    $UserDetails=Import-Csv “Buser.csv” #—–importeren van bulkusers data
    
    foreach($UD in $UserDetails) 
    { #——–looping in de csv bestand en
    
       # alle data doorgeven
       $CN=$UD.CN
       $SN=$UD.SN
       $title=$UD.title
       $description=$UD.description
       $department=$UD.department
       $streetAddress=$UD.streetAddress
       $postalcode=$UD.postalcode
       $telephoneNumber=$UD.telephoneNumber
       $givenName=$UD.givenName
       $company=$UD.company
       $mail=$UD.mail
       $homePhone=$UD.homePhone
       $mobile=$UD.mobile
       $userPrincipalName=$UD.userPrincipalName
       $Samaccountname=$UD.Samaccountname
    
       #Skipped alle accounts die al bestaan
       if ([adsi]::Exists("LDAP://localhost:389/cn=$cn,ou=Test,dc=oxl,dc=local"))
       {
           #de extra eigenschappen
           write-host $CN word bijgewerkt
           $ConUser.Put(“sAMAccountName”,$Samaccountname)
           $ConUser.put(“SN”,$SN)
           $ConUser.put(“Title”,$Title)
           $ConUser.put(“Description”,$description)
           $ConUser.put(“department”,$department)
           $ConUser.put(“streetAddress”,$streetAddress)
           $ConUser.put("PostalCode",$postalcode)
           $ConUser.put("telephoneNumber",$telephoneNumber)
           $ConUser.put("givenName",$givenName)
           $ConUser.put("company",$company)
           $ConUser.put("mail",$mail)
           $ConUser.put("homePhone",$homePhone)
           $ConUser.put("mobile",$mobile)
           $ConUser.put("userPrincipalName",$userPrincipalName)
    
           $ConUser.setinfo() #Zet alle data erin
           write-host $CN is bijgewerkt
       }
       else
       {
           $ConUser=$connection.create(“user”,”cn=$cn”) #Eerst word de gebruiker gemaakt en dan pas
    
           #de extra eigenschappen
           write-host $CN word aangemaakt
           $ConUser.Put(“sAMAccountName”,$Samaccountname)
           $ConUser.put(“SN”,$SN)
           $ConUser.put(“Title”,$Title)
           $ConUser.put(“Description”,$description)
           $ConUser.put(“department”,$department)
           $ConUser.put(“streetAddress”,$streetAddress)
           $ConUser.put("PostalCode",$postalcode)
           $ConUser.put("telephoneNumber",$telephoneNumber)
           $ConUser.put("givenName",$givenName)
           $ConUser.put("company",$company)
           $ConUser.put("mail",$mail)
           $ConUser.put("homePhone",$homePhone)
           $ConUser.put("mobile",$mobile)
           $ConUser.put("userPrincipalName",$userPrincipalName)
    
           $ConUser.setinfo() #Zet alle data erin
           write-host $CN is aangemaakt
       }
    }

    Dit is aardig wat code, maar de helft werkt in ieder geval. Ik meot alleen de else gedeelte werkende krijgen zonder deze foutmelding:

    PS C:\Users\administrator.OXL\Desktop\Scripting LAB\test_area\Full CSV to AD> C:\Users\administrator.OXL\Desktop\Scripting LAB\test_area\Full CSV to AD\FULL.ps1
    John McDee word bijgewerkt
    Exception calling "setinfo" with "0" argument(s): "The object already exists.
    "
    At C:\Users\administrator.OXL\Desktop\Scripting LAB\test_area\Full CSV to AD\FULL.ps1:46 char:25
    +         $ConUser.setinfo <<<< () #Zet alle data erin
       + CategoryInfo          : NotSpecified: ( [], MethodInvocationException
       + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
    
    John McDee is bijgewerkt
    Jan Vermeen word bijgewerkt
    Exception calling "setinfo" with "0" argument(s): "The object already exists.
    "
    At C:\Users\administrator.OXL\Desktop\Scripting LAB\test_area\Full CSV to AD\FULL.ps1:46 char:25
    +         $ConUser.setinfo <<<< () #Zet alle data erin
       + CategoryInfo          : NotSpecified: ( [], MethodInvocationException
       + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
    
    Jan Vermeen is bijgewerkt
    Daniel Limvries word bijgewerkt
    Exception calling "setinfo" with "0" argument(s): "The object already exists.
    "
    At C:\Users\administrator.OXL\Desktop\Scripting LAB\test_area\Full CSV to AD\FULL.ps1:46 char:25
    +         $ConUser.setinfo <<<< () #Zet alle data erin
       + CategoryInfo          : NotSpecified: ( [], MethodInvocationException
       + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
    
    Daniel Limvries is bijgewerkt
    Mark Denvel word bijgewerkt
    Exception calling "setinfo" with "0" argument(s): "The object already exists.
    "
    At C:\Users\administrator.OXL\Desktop\Scripting LAB\test_area\Full CSV to AD\FULL.ps1:46 char:25
    +         $ConUser.setinfo <<<< () #Zet alle data erin
       + CategoryInfo          : NotSpecified: ( [], MethodInvocationException
       + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
    
    Mark Denvel is bijgewerkt
    Kevin Bloot word bijgewerkt
    Exception calling "setinfo" with "0" argument(s): "The object already exists.
    "
    At C:\Users\administrator.OXL\Desktop\Scripting LAB\test_area\Full CSV to AD\FULL.ps1:46 char:25
    +         $ConUser.setinfo <<<< () #Zet alle data erin
       + CategoryInfo          : NotSpecified: ( [], MethodInvocationException
       + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
    
    Kevin Bloot is bijgewerkt
    

    Zoals jullie zien zegt Powershell dat ik geen argumenten door stuur wat vreemd is.

    Indien iemand dit na wilt doen dan zal je ook de CSV bestand nodig hebben die ik hieronder wel neerzet:

    CN,SN,GivenName,Name,Title,Description,PostalCode,TelephoneNumber,Department,Company,StreetAddress,Countrycode,SamAccountName,userPrincipalName,Mail,HomePhone,mobile,HomeDirectory
    John McDee,McDee,John,John,ICT,ICT in OXL,2929xc,0180 5555555,ICT,Outdoor XL,Jan Steenstraat 3,NL,John,john@oxl.local,john@gmail.com,0180 555555,06 88888888,c:\testgebruikers\nathan
    Jan Vermeen,Vermeen,Jan,Jan,Stagiaire,Stagiaire voor 2 maanden,2121da,0180 9999999,Stagiaire,Outdoor XL,Ludico straat 56,NL,Jan,jan@oxl.local,jan@gmail.com,0180 999999,06 22222222,c:\testgebruikers\jan
    Daniel Limvries,Limvries,Daniel,Daniel,Stagiaire,Stagiaire voor 2 maanden,2121da,0180 9999999,Stagiaire,Outdoor XL,Warden single,NL,Daniel,Daniel@oxl.local,Daniel@gmail.com,0180 999999,06 22222222,c:\testgebruikers\daniel
    Mark Denvel,Denvel,Mark,Mark,Baas,Baas binnen OXL,2323sa,0180 829384,Bazen,Outdoor XL,Aalborg 1,NL,Mark,Mark@oxl.local,Mark@gmail.com,0180 923847,06 83474742, c:\testgebruikers\mark
    Kevin Bloot,Bloot,Kevin,Kevin,Verkoper,Verkoper binnen OXL,1345tr,0180 5573223,Verkoper,Outdoor XL,Antonis straat,NL,Kevin,Kevin@oxl.local,Kevin@gmail.com,0180 5444988,06 22553535, c:\testgebruikers\kevin
    

    Alles staat ook nog eens in de bijlage voor wat extra gemak. -----> [ATTACH]10695[/ATTACH]

    Jullie zijn GEWELDIG als jullie mij kunnen helpen al is dit enorm lastig.

    Alvast bedankt.

    Full CSV to AD.rar

×
×
  • Nieuwe aanmaken...

Belangrijke informatie

We hebben cookies geplaatst op je toestel om deze website voor jou beter te kunnen maken. Je kunt de cookie instellingen aanpassen, anders gaan we er van uit dat het goed is om verder te gaan.