From cc18424f65d55fbc262ea9eb76f7df3477f14cf6 Mon Sep 17 00:00:00 2001 From: sussurro Date: Sun, 27 Jun 2021 15:55:15 -0400 Subject: [PATCH] updates a check to see if user exists --- AD_Users_Create/CreateUsers.ps1 | 13 ++++++++++++- Invoke-BadBlood.ps1 | 6 ++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/AD_Users_Create/CreateUsers.ps1 b/AD_Users_Create/CreateUsers.ps1 index 49c5ed4..5783db6 100644 --- a/AD_Users_Create/CreateUsers.ps1 +++ b/AD_Users_Create/CreateUsers.ps1 @@ -259,6 +259,16 @@ if ($passwordinDesc -lt 10) { $description = 'Just so I dont forget my password is ' + $pwd }else{} + + $exists = $null + try { + $exists = Get-ADUSer $name -ErrorAction Stop + } catch{} + + if($exists){ + return $true + } + new-aduser -server $setdc -Description $Description -DisplayName $name -name $name -SamAccountName $name -Surname $name -Enabled $true -Path $ouLocation -AccountPassword (ConvertTo-SecureString ($pwd) -AsPlainText -force) @@ -276,6 +286,7 @@ try{Set-ADUser -Identity $name -UserPrincipalName "$upn" } catch{} + return $false ################################ #End Create User Objects ################################ @@ -283,4 +294,4 @@ } - \ No newline at end of file + diff --git a/Invoke-BadBlood.ps1 b/Invoke-BadBlood.ps1 index 61e16e1..f81e3de 100644 --- a/Invoke-BadBlood.ps1 +++ b/Invoke-BadBlood.ps1 @@ -108,9 +108,11 @@ if ($badblood -eq 'badblood') { .($basescriptPath + '\AD_Users_Create\CreateUsers.ps1') $createuserscriptpath = $basescriptPath + '\AD_Users_Create\' do { - createuser -Domain $Domain -OUList $ousAll -ScriptDir $createuserscriptpath + $status = createuser -Domain $Domain -OUList $ousAll -ScriptDir $createuserscriptpath Write-Progress -Activity "Random Stuff into A domain - Creating $UserCount Users" -Status "Progress:" -PercentComplete ($x / $UserCount * 100) - $x++ + if($status -eq $false){ + $x++ + } }while ($x -lt $UserCount) #Group Creation