Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $output = ""
- "" | Out-File -FilePath "c:\scripts\output.txt"
- #$secpass = Read-Host "Password" -AsSecureString
- Import-Csv C:\scripts\attributetest.csv |
- foreach {
- $name = "$($_.FirstName) $($_.LastName)"
- $SamAccountName = "$($_.FirstName)$($_.LastName)"
- $Password = "$($_.Password)"
- $user = Get-ADUser -filter {SamAccountName -eq $SamAccountName}
- $ProxyAddress = ("SMTP:$SamAccountName@ryan.test.com")
- $ProxyAddress2 = ("smtp:$SamAccountName@hogarthww.mail.onmicrosoft.com")
- $TargetAddress = ("SMTP:$SamAccountName@hogarthww.mail.onmicrosoft.com")
- $ddmm = (Get-Date -UFormat "%d%m")
- $email = "$($_.FirstName.ToLower()).$($_.LastName.ToLower())@hogarthww.com"
- if($user) {
- $SamAccountName = "$($_.FirstName)$($_.LastName)$ddmm"
- $name = "$($_.FirstName) $($_.LastName)$ddmm"
- $ProxyAddress = "SMTP:$($_.FirstName)$($_.LastName)$ddmm@hogarthww.com"
- $ProxyAddress2 = "smtp:$($_.FirstName)$($_.LastName)$ddmm@hogarthww.mail.microsoft.com"
- $email = "$($_.FirstName.ToLower()).$($_.LastName.ToLower())$ddmm@hogarthww.com"
- }
- New-ADUser -GivenName $($_.FirstName) -Surname $($_.LastName) `
- -name $name -SamAccountName $SamAccountName -UserPrincipalName "$($SamAccountName)@ryan.test.com" `
- -OtherAttributes @{'ProxyAddresses'=("$ProxyAddress"),"$ProxyAddress2"} `
- -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -Force) -Path "ou=Users,ou=HogarthWW,dc=ryan,dc=test,dc=com" `
- -Enabled:$true
- $output += "User account has been created, details are as follows:`r`n`r`nemail: $email`r`nlogin:`r`npassword:$Password`r`n`r`nThanks,`r`nRyan.`r`n`r`n`r`n"
- }
- $output | Out-File -FilePath "c:\scripts\output.txt"
- c:\scripts\output.txt
Add Comment
Please, Sign In to add comment