powershell - generate next available samaccountname in increments -


i trying generate next available ad account using incremental numbers. example, domain has accounts names"opr1000-opr1014", when run script, should expect opr1015, instead gets stuck in loop , never returns value. have running while loop , increasing numerical value in increments until finds unused value @ point while loop should no longer true , script should end. have ideas?

    $account = "opr" $accountnum = "1000" $accountname = $account + $accountnum $accountint = $account + $int $int = [system.decimal]::parse($accountnum) do{     $query = "(&(objectclass=user)(samaccountname=$accountname))"     $result = ([adsisearcher]$query).findone()     if($result){$int++} }while($accountint)  "$account$int" 

there quite few mistakes, see this:

$account = "opr" $accountnum = 1000 {     $accountname = $account + $accountnum;     $query = "(&(objectclass=user)(samaccountname=$accountname))"     $result = ([adsisearcher]$query).findone()     if($result -eq $false)      {       break     }     $accountnum++ } while($true) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -