-3

Basicly what I want is to search a given OU and determinate what should be the next computername.

We have computer objects named like: LONDON10, LONDON11, LONDON12.

Its a bit tricky however because we also deletet old computer objects. So lets say there is no LONDON03 and my last computer which was installed is named LONDON25. So the next should be LONDON26 and not LONDON03.

Bonus part that we name our notebooks like NB-LONDON01, NB-LONDON02 etc.

Any help would be appreciated :)

Tas Varga
  • 3
  • 1

1 Answers1

-1

I don't have the AD cmdlets in my current role, so you may need to tweak that, but it should look something like this:

$nextNumber =  (Get-ADComputer -Filter * -SearchBase "OU=IT, DC=contoso, DC=com" |% { if ($_.name -match '^(?:NB-)?LONDON([0-9]+)$' ) {[Int]$Matches[1]} } | measure -Maximum).Maximum + 1

If you need to alter the RegEx, I suggest using http://regexstorm.net/tester

Graham
  • 447
  • 4
  • 8