Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

import users into AD

$
0
0

anyone, please help me on this script

 

 the script :::

 

Import-Module ActiveDirectory 

 

$TXT = Import-Txt -Delimiter "0100" -Path "$mybooks.txt" 

$AD = Get-ADUser -Filter * -SearchBase "OU=testou,DC=domainName,DC=lcl" 

 

$Exists = "0" 

 

 

foreach ($user in $TXT)  

    foreach ($UserNeu in $AD)  

    { 

        if ($User.Sam -eq $UserNeu.SAMaccountname) 

        {  

            $Exists = "1" 

        } 

 

    }  

      if ($Exists -eq "0")  

      { 

              $OU = "OU=testou,DC=" + $User.Domain + ",DC=lcl" 

              $Department = $User.Department

              $displayname = $User.LastName + " " + $User.FirstName 

              $Password = $abc123

              $UPNsuffix = $User.upnsuffix 

              $UPN = $User.SAM + "@" + $UPNsuffix 

 

              New-ADUser 

              -FullName $User.FullName -SamAccountName $user.SAM -UserPrincipalName $UPN -DisplayName $FullName -GivenName $user.FirstName -Surname $user.LastName -Description $user.Description -Office $user.Unit -OfficePhone $user.OfficePhone -MobilePhone $user.MobilePhone -StreetAddress $user.StreetAddress -City $user.City -State $user.State -PostalCode $user.Postcode -Department $user.department -Company $user.company -Enabled $true -Path $OU 

              #Add-ADGroupMember -Identity $user.securitygroup -Member $user.SAM 

       }   

       }  

      else 

      {  

      $Exists = "0" 

      } 

 }


Viewing all articles
Browse latest Browse all 8411

Trending Articles