Как создать учётные записи с помощью powershell в AD из csv

Import-Csv -Path C:\1.csv -Encoding Default -Delimiter ";" | sort CN |
foreach-object{
#New-ADUser -Name $_.Full_Name -AccountPassword (ConvertTo-SecureString 'password!' -AsPlainText -force) -CannotChangePassword $True -Description $_.Desc -DisplayName $_.Full_Name -EmailAddress $_.Email -Enabled $False -GivenName $_.First_Name -HomeDirectory $_.Homedir -HomeDrive $Homedri -PasswordNeverExpires $True -Path $_.Path -SamAccountName $_.Email -ScriptPath LogonS.cmd -Surname $_.Last_Name -UserPrincipalName $_.Email -passthru
#Write-Host $_.SamAccountName
$filter="SamAccountName -eq '"+$_.SamAccountName+"'"
$usrexist=get-aduser -filter $filter
#Write-Host $_.SamAccountName
#Write-Host $_.SamAccountName
if ($usrexist -eq $null)
{
Write-Host "Username" $_.CN "not exists " $_.SamAccountName.Length
if ($_.SamAccountName.Length -gt 20 ) { $_.SamAccountName=$_.SamAccountName.Substring(0,20)
Write-Host $_.SamAccountName}
if (!$_.emailaddress){ $_.emailaddress=$_.SamAccountName+'@domen.ru'}
# write-host -Name $_.CN -DisplayName $_.DisplayName -City $_.City -Department $_.Department -Surname $_.Surname -GivenName $_.Givenname -SamAccountName $_.SamAccountName -EmailAddress $_.emailaddress -Title $_.title -MobilePhone $_mobile -AccountPassword (ConvertTo-SecureString 'password' -AsPlainText -force) -Path "OU=Temp,DC=namedomen,DC=ru" -UserPrincipalName $_.emailaddress -Enabled $true -ChangePasswordAtLogon $true
new-aduser -Name $_.CN -DisplayName $_.DisplayName -City $_.City -Department $_.Department -Surname $_.Surname -GivenName $_.Givenname -SamAccountName $_.SamAccountName -Title $_.title -POBox $_postOfficeBox -AccountPassword (ConvertTo-SecureString 'password!' -AsPlainText -force) -Path "OU=Temp,DC=namedomen,DC=ru" -UserPrincipalName $_.emailaddress -Enabled $true -ChangePasswordAtLogon $true
}
else
{
 
Write-Host "Username" $_.CN "exists" -ForegroundColor red -BackgroundColor white
 
}

 

Similar Posts: