1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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 "Secreto@123@Top" -AsPlainText -force) -Enable $true } |