Forum Discussion

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

Re: Generate Unified Group by number....

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?

2 Replies

  • 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