

$dateTextMonth = Get-Date -Date (Get-Date).AddMonths(-1) -format MMMM I like to have the month name start with a capital letter, thus I add the third line of code: To get the name of the month and the year, use the following two lines. ::CurrentThread.CurrentCulture = $CurrentCulture ::CurrentThread.CurrentCulture = "en-US"Īnd after the script finishes, I’ll set it back like this: So, in the beginning of the script I’ll have these lines: I’ll first save the CurrentCulture setting in a variable, so I can change it back after the script finishes. When working with Excel and PowerShell, when you’re living outside of the US, make sure you set the CurrentCulture to EN-US, otherwise you’ll get several Excel errors. Make sure macros are enabled within Excel, otherwise they’ll be disabled when opening the Excel file which will result in the script not working. I needed a way to open an Excel file and run one of the macro’s inside the file to do some calculations and import some data then save the file as a new file, with the name of the previous month and its year added to it, to differentiate it from the original file.
