#The first day of the month#.......................................... It was the first day of the year .#(get-date 0). AddYears ((get-date). YEAR-1). AddMonths ((get-date). MONTH-2)#The last day of the month#...................................................................... It was the first day of the year before we arrived .#(get-date 0). AddYears ((get-date). YEAR-1). AddMonths ((get-date). MONTH-1). AddDays ( -1)$lognames="Application","Security","System"$lastmonthfirstday= (get-date 0). AddYears ((get-date). YEAR-1). AddMonths ((get-date). Month-2)$lastmonthlastday= (get-date 0). AddYears ((get-date). YEAR-1). AddMonths ((get-date). MONTH-1). AddDays (-1)foreach($logname inch $lognames) {Get-eventlog-computername$env: COMPUTERNAME-logname$logname-after$lastmonthfirstday-before$lastmonthlastday| Export-csv-path ("C:\EventLog\"+$lastmonthfirstday. Year +"_"+$lastmonthfirstday. Month +"_"+$env: COMPUTERNAME+"_"+$logname+". CSV")}
Export Windows logs to a CSV file by month