I'm currently using get-date to run reports on past events by subtracting the number of days from the current day. I'd like to make the report run so that it automatically determines what the previous month was, and captures all events for that date range.
For example, if it is February 6th, make the report capture data from January 1st to January 31st. If it is March 23rd, make the report capture events from February 1st to February 28th.
Is this possible? here is my current statement:
Get-VIEvent -Start (Get-Date).AddDays(-35) -Finish (Get-Date).AddDays(-5)
Thanks
Try something like this
$now = Get-Date -Hour 0 -Minute 0 -Second 0
$daysBack = - $now.Day + 1
$Start = $now.AddMonths(-1).AddDays($daysBack)
$DaysInMonth = [DateTime]::DaysInMonth($Start.Year,$Start.Month)
$Finish = $Start.AddDays($DaysInMonth)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
$now = Get-Date -Hour 0 -Minute 0 -Second 0
$daysBack = - $now.Day + 1
$Start = $now.AddMonths(-1).AddDays($daysBack)
$DaysInMonth = [DateTime]::DaysInMonth($Start.Year,$Start.Month)
$Finish = $Start.AddDays($DaysInMonth)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use:
$Finish = Get-Date -Day 1 -Hour 0 -Minute 0 -Second 0
$Start = $Finish.AddMonths(-1)
Get-VIEvent -Start $Start -Finish $Finish
OK great thanks again