$cred = Get-Credential
$server = "ЧЧЧЧЧЧ"
$OUPath = "OU=Computers,OU=ЧЧЧЧ,OU=ЧЧЧЧ ЧЧЧ,DC=ЧЧЧЧЧ"
$check0 = Get-ADComputer $env:COMPUTERNAME -Credential $cred -Server $server
$NullOrEmpty0 = [string]::IsNullOrEmpty($check0)
$min=0
$max=4000
$2 = $min..$max | %{
$leght = "$_".Length
if ($leght -eq 1) { "ЧЧ-ЧЧЧ-A000" + "$_" }
if ($leght -eq 2) { "ЧЧ-ЧЧЧ-A00" + "$_" }
if ($leght -eq 3) { "ЧЧ-ЧЧЧ-A0" + "$_" }
if ($leght -eq 4) { "ЧЧ-ЧЧЧ-A" + "$_" }
}
if($NullOrEmpty0 -eq $true ){
$3 = $2 | %{
$check=@()
$check=get-ADComputer $_ -Credential $cred -Server $server
$NullOrEmpty = [string]::IsNullOrEmpty($check)
if($NullOrEmpty -eq $true){$_}
}
$4 = $3|get-random
Add-Computer -DomainName ozon -DomainCredential $cred -NewName $4 -OUPath $OUPath -Restart
}