If you need to format a number in Powershell to include leading zeros, so that the length is always a fixed width, it is easy to do with Powershell format operator.

I was working with some data that stored dates as single digits for those days and months that only contained a single digit. For example I needed “1/1/2019” to be “01/01/2019”.

Using the powershell “-f” operator it is easy to add the leading zeros. For example:

PS C:\> "{0:d2}/{1:d2}/{2:d4}" -f 1,1,2019 01/01/2019

You can easily wrap this in a loop like this:

foreach ($months in @(1..12)) { $Month = "{0:d2}" -f $months foreach ($days in @(1..31)) { $Day = "{0:d2}" -f $days $ArchiveFolder = "D:\Archive\PDF\2019\$month\$day" Write-Host $ArchiveFolder } }