Skip to content

Instantly share code, notes, and snippets.

@gonzaleztroyano
Created November 15, 2021 22:10
Show Gist options
  • Save gonzaleztroyano/dfd480e72e62e94e7fa863d725330850 to your computer and use it in GitHub Desktop.
Save gonzaleztroyano/dfd480e72e62e94e7fa863d725330850 to your computer and use it in GitHub Desktop.
foreach ($linea in Get-Content 'Z:\Comandos PS\dominioASO.txt'){
$campos = $linea.Split("#")
$apellido = $campos1
$ruta = "OU="+$campos[3]+","+"DC=ASO,DC=LOCAL"
[string]$samid = $campos[2]
$ou = $campos[3]
$existe = 'n'
Get-ADOrganizationalUnit -Filter * | Foreach-Object `
-Process{
if($_.Name -ieq $ou){
Write-Host $_.Name "Ya existe"
$existe = "s"
}
}
if($existe -eq "n"){
Write-Host "Creando unidad organizativa " $ou
New-ADOrganizationalUnit $ou -ProtectedFromAccidentalDeletion $false
}
New-ADUser -Name $samid -Path $ruta -GivenName $campos[0] -Surname $campos[1] -DisplayName $samid -AccountPassword(ConvertTo-SecureString -AsPlainText "hol@Caracol4" -Force) -HomePhone $campos4 -ChangePasswordAtLogon $true -StreetAddress $campos[6]
# Add-ADGroupMember -Identity $rutagrupo -Members $samid
Write-Host $samid "hecho"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment