foreach($operacion in Get-Content file.txt){ $lineSplit = $operacion.Split(",") if($lineSplit[0] -eq "ou"){ New-ADOrganizationalUnit -Name $lineSplit[1] -Path "dc=red,dc=local" -WhatIf }elseif($lineSplit[0] -eq "user"){ $userTest = $lineSplit[1] if(Get-ADUser -LDAPFilter "(samaccountname=$userTest)"){ echo "Existe" }else{ New-ADUSer -Name $lineSplit[1] -Sam $lineSplit[1] -Path ("OU="+$lineSplit[2]+",dc=red,dc=local") ` -AccountPassword (ConvertTo-SecureString "[email protected]@Top" -AsPlainText -force) -Enable $true }
Ejercicios de PowerShell: crear usuarios y unidades organizativas en un Directorio Activo (Usuarios, PowerShell)
Except where otherwise noted, Jesusninoc by Jesús N. is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.