Forum Discussion

Jesper Stein's avatar
Jesper Stein
Brass Contributor
Aug 23, 2018

Generate Unified Group by number....

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?

  • Jesper Stein's avatar
    Jesper Stein
    Brass Contributor

    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?

    • Mattias Borg's avatar
      Mattias Borg
      Brass Contributor

      Hi,

       

      here's an example how to solve leading zeros

      1..100 | %{

      $number =  "{00:D5}" -f $_
      Write-Host $number
      }

      • Mattias Borg's avatar
        Mattias Borg
        Brass Contributor

        so if you run that it will give you an idea how to solve your challenge

Resources