以增量方式生成下一个可用的 samaccountname
generate next available samaccountname in increments
我正在尝试使用增量数字生成下一个可用的广告帐户。例如,我的域当前有帐户名称 "opr1000-opr1014",因此当我 运行 我的脚本时,我应该期待 opr1015,但它陷入循环并且永远不会 returns 值。我有它 运行 一个 do while 循环并以增量方式增加数值,直到它找到一个未使用的值,此时 do while 循环不再为真并且脚本应该结束。有人有什么想法吗?
$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"
错误比较少,看这个:
$Account = "opr"
$Accountnum = 1000
do
{
$Accountname = $Account + $Accountnum;
$query = "(&(objectClass=user)(samaccountname=$Accountname))"
$result = ([adsisearcher]$query).FindOne()
if($result -eq $false)
{
break
}
$Accountnum++
} while($true)
$Account = "opr"
$Accountnum = 1000
do
{
$Accountname = $Account + $Accountnum;
$query = "(&(objectClass=user)(samaccountname=$Accountname))"
$result = ([adsisearcher]$query).FindOne()
if($result)
{
$Accountnum++
}else{
break
}} while($true)
"$Account$Accountnum"
我正在尝试使用增量数字生成下一个可用的广告帐户。例如,我的域当前有帐户名称 "opr1000-opr1014",因此当我 运行 我的脚本时,我应该期待 opr1015,但它陷入循环并且永远不会 returns 值。我有它 运行 一个 do while 循环并以增量方式增加数值,直到它找到一个未使用的值,此时 do while 循环不再为真并且脚本应该结束。有人有什么想法吗?
$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"
错误比较少,看这个:
$Account = "opr"
$Accountnum = 1000
do
{
$Accountname = $Account + $Accountnum;
$query = "(&(objectClass=user)(samaccountname=$Accountname))"
$result = ([adsisearcher]$query).FindOne()
if($result -eq $false)
{
break
}
$Accountnum++
} while($true)
$Account = "opr"
$Accountnum = 1000
do
{
$Accountname = $Account + $Accountnum;
$query = "(&(objectClass=user)(samaccountname=$Accountname))"
$result = ([adsisearcher]$query).FindOne()
if($result)
{
$Accountnum++
}else{
break
}} while($true)
"$Account$Accountnum"