Our organisation renames all new computers before they join our domain and I am trying to create a script to display the next available number.
So, our naming convention is as follows
Example:
GBYOR-DT1
GB - YOR - DT - 1
[Country] [City] [Desktop] [Number]
However my predecessor thought to number these in no logical order and that just isn't happening on my watch. (Did someone say OCD?)
Currently I run
> Get-ADComputer -Filter * | where{$_.Name -Like "GBYOR-DT*" | FL Name | Export-CSV -Path "X Location"
I then go into Excel, split the cells and the sort numerically.
What I would like is to create a script that just shows me the next available number.
For example, as it currently stands, we have X number of machines, one is GBYOR-DT4
, another is GBYOR-DT245
but there is no GBYOR-DT15
.
I would like to script this so that when I run it, it will look at all of the machines registered on our domain and then display the next one
> GBYOR-DT1
> GBYOR-DT2
> GBYOR-DT3
> GBYOR-DT4
> GBYOR-DT6
>
> ...GBYOR-DT5 does not exist so this is the next number to use for renaming.
Any help would be appreciated.