SHARE
TWEET

Untitled

a guest May 23rd, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Param(
  2. $LastRuntime)
  3. Import-module activedirectory
  4. $dataSource = “XXXXXXXXXX”
  5. $user = “XXXX”
  6. $pwd = “XXXXXXXXX”
  7. $database = “XXXXXXXXX”
  8. $connectionString = “Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;”
  9. $connection = New-Object System.Data.SqlClient.SqlConnection
  10. $connection.ConnectionString = $connectionString
  11. $connection.Open()
  12. $query = “SP_GetUsers"
  13. $command = $connection.CreateCommand()
  14. $command.CommandText = $query
  15. $command.Parameters.AddWithValue("@LastRunTime", $LastRuntime) | Out-Null
  16. $result = $command.ExecuteReader()
  17. foreach ($User in $result)            
  18. {          
  19.     $Displayname =  $User.Lastname + ", " +  $User.Firstname            
  20.     $UserFirstname = $User.Firstname
  21.        $UserFirstIntial = $UserFirstname.Substring(1,1)
  22.        $Usermiddlename = $User.Middlename
  23.     $UserLastname = $User.Lastname            
  24.     $OU = $User.OU
  25.     $SAM = $User.SAM      
  26.     $UPN = $UserFirstname.Substring(1,1) + $User.Lastname + "@" + $User.Maildomain            
  27.     $Description = $User.Description            
  28.     $Password = $User.Password
  29.    
  30.     #Creation of the account with the requested formatting.
  31.     New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamAccountName $SAM -Office "Office"  -UserPrincipalName $UPN -GivenName "$UserFirstname" -Surname "$UserLastname" -Description "$Description" -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path "$OU" -ChangePasswordAtLogon $True –PasswordNeverExpires $false -server server.domain.local            
  32.        $Displayname
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top