Powershell changing Date to the first of last month when the script runs [duplicate]
If I run the script on 2/4/2013or any other day in February I want the date to be change to 1/1/2013. I am replacing date on line 59 with this value.
#Get the content of the CMS Script.
$CMSReport = Get-content C:\reports\CMSReport.acsauto
# Go to line 59 and replace the date for Last Month date.
$CMSReport[58] = $CMSReport[58] -replace "([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d", [datetime]::Today.ToShortDateString()
$CMSReport | Set-Content C:\reports\testCMS.acsauto
#Run the CMS script
Invoke-Expression -command "c:\reports\testCMS.acsauto"
Get the value, parse it as a date, AddMonths(-1), put it back. Replace is not the way to go here.