SHARE
TWEET

Untitled

a guest Oct 23rd, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Csv Bulkuser.csv | foreach-object {
  2. $userprincipalname = $_.SamAccountName + "@" + $_.Domain
  3. $displayname = $_.Name + " " + $_.Surname
  4. $password = $_.password
  5. $HomeDirectory = $_.HomeDirectory + $_.SamAccountName
  6. $Username = $_.SamAccountName
  7. $ProfilePath = "\\Filtjener\Roaming user profiles\" + $Username
  8. New-Item -Path $_.HomeDirectory -Name $UserName -ItemType Directory -ErrorAction SilentlyContinue
  9. New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprincipalname -ProfilePath $ProfilePath -Name $displayname -Surname $_.Surname -DisplayName $displayname -GivenName $_.Name -MobilePhone $_.MobilePhone -EmailAddress $userprincipalname -Description $_.Description -Department $_.Department -Path $_.Path -AccountPassword (ConvertTo-SecureString "$password" -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -Homedrive "Z" -HomeDirectory $HomeDirectory -PassThru }
  10.  
  11. #start-sleep pause før neste linje kjøres.
  12. start-sleep -milliseconds 300
  13.  
  14. #Produksjonsbrukere inn i produksjon-global
  15. Get-ADUser -SearchBase ‘OU=Fast Ansatte,OU=Produksjon,OU=Brukere,OU=Bedrift,DC=opmeis,DC=local’ -Filter * | ForEach-Object {Add-ADGroupMember -Identity ‘produksjon-global’ -Members $_}
  16.  
  17. #Salgbrukere inn i salg-global
  18. Get-ADUser -SearchBase ‘OU=Salg,OU=Brukere,OU=Bedrift,DC=opmeis,DC=local’ -Filter * | ForEach-Object {Add-ADGroupMember -Identity ‘salg-global’ -Members $_}
  19.  
  20. #Administrasjonsbrukere inn i administrasjon
  21. Get-ADUser -SearchBase ‘OU=Administrasjon,OU=Brukere,OU=Bedrift,DC=opmeis,DC=local’ -Filter * | ForEach-Object {Add-ADGroupMember -Identity ‘administrasjon-global’ -Members $_}
  22.  
  23. #Tekniskbrukere inn i teknisk
  24. Get-ADUser -SearchBase ‘OU=Teknisk Utviklingsavdeling,OU=Brukere,OU=Bedrift,DC=opmeis,DC=local’ -Filter * | ForEach-Object {Add-ADGroupMember -Identity ‘teknisk-global’ -Members $_}
  25.  
  26. Write-Host "Hele scriptet har blitt kjørt, brukere har blitt opprettet og lagt inn i grupper"
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