Background story, I'm using gci to get part of the file name from all the files in folders named '2023' and exporting to CSV. I'm getting the first value after '.' within the file name. The leading zeros are being stripped when I open the file in Excel but not in Notepad++. I tried applying the logic from this post
File name: 12345.001.chris_comp.NY.2023_08_22.xlsx
Current output: 1
Desired output: 001
#splitFile
$numberedFolder = 'C:\Users\cthor\OneDrive\Documents\PowerShell\Test'
$outputFile = "C:\Users\cthor\OneDrive\Documents\PowerShell\Results\results_$(Get-Date -f yyyy-MM-dd-hh-mm-ss).csv"
Get-ChildItem -Directory -Recurse -LiteralPath $numberedFolder -Filter '2023' |
Get-ChildItem -File |
Select-Object @{name='process id';Expression={'{0:d3}' -f [int] $_.Name.Split('.')[1]}} | #preverse leading 0's.
Export-Csv -Path $outputFIle -Append -NoTypeInformation
UPDATE: I came across another post that adds a tab in front which seems like a workaround. I tested it and it does work, maybe just knowing it's a workaround has tainted my view on it lol.
replace '{0:d3}' with "`t{0:d3}"