1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Add-Type -AssemblyName System.DirectoryServices.AccountManagement $account = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([DirectoryServices.AccountManagement.ContextType]::Domain, $env:userdomain) #'pepito', 'Secreto@123@Top' if($account.ValidateCredentials((Read-Host "intro usuario"), (Read-Host "introduce pass"))){ 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 } } |