Aug 22 2018 11:02 PM
Hi guys
I'm creating a script that will create new UnifiedGroups in a format where its named Group_0001, Group_0002 and so on. We will the set the DisplayName to what ever the user want.
But I don't know how to generate a value +1 to the count I do:
$GroupNumber = Get-UnifiedGroup -Filter {Name -like "Group_000*"}
$GroupCount = $GroupNumber.count
When naming the the new group I want to generate the name as "Group_000{$Groupcount +1} (just writing rubbish to show what I'm trying to do).
Anyone have an idea on how to do this?
Aug 22 2018 11:51 PM
Okay, so perhaps I was a little too fast.
Now I have this script:
$DisplayName = "Group_TESTE222"
$GroupNumber = Get-UnifiedGroup -Filter {Name -like "Group_00*"}
$GroupCount = $GroupNumber.count
$GroupName = ($GroupCount +1)
New-UnifiedGroup -Name ('Group_000' + $GroupName) -displayname "$DisplayName" -WhatIf
The $DisplayName value will be coming from a csv file in the end but just put in for now. This works in a way, but of course when I generate group number 10 the name is Group_00010 and not what I want it to be = Group_0010.
I'm a little stuck on how to do this so it counts up correct?
Aug 24 2018 03:35 AM
Hi,
here's an example how to solve leading zeros
1..100 | %{
$number = "{00:D5}" -f $_
Write-Host $number
}
Aug 24 2018 03:53 AM
so if you run that it will give you an idea how to solve your challenge