I’m trying to get the current quarter placed in a file name.
I’ve assigned the year and current quarter number to two different variables so I can use them as I please anywhere as well (such as renaming a folder, to reference a file/folder, etc.)
Current File is:
FileName.csv
My code:
$QYear = $(Get-date -f yyyy)
$QNum = [int][math]::Ceiling($today.Month/3)
$file1 = “file1.csv”
$file2 = “$QYear-Q$QNum-FileName(distrubution).csv”
Import-CSV $lineCount | Select-Object 'LineCount', 'Name' | Export-Csv $file2 #I was reordering columns
Current Output:
2023-Q3-FileName.csv
Desired output:
2023Q3FileName.csv
>Solution :
Change this string expression:
$file2 = "$QYear-Q$QNum-FileName(distrubution).csv"
to:
$file2 = "${QYear}Q${QNum}FileName(distrubution).csv"
By using { } as qualifiers around the variable name, you prevent PowerShell from trying to resolve $QYearQ or $QNumFileName
hey
cool blog 🙂 will give it a follow and a like !