Hey all, I was wondering if I could pick some brains about a script I' m being asked to write at work. The script needs to do a full backup on Sunday and incremental backups Mon-Sat. But it also has to keep two different sets of backups going, so week 1, week 2, week 3 overwrites week 1, ect. This is what I have so far but I'm having trouble getting Powershell to identify the day of the week.
$HN = Hostname
$b = Get-Date -Format "yyyy-MM-dd"
$a = Get-Date
"Day: " + $a.Day
"Month: " + $a.Month
"Year: " + $a.Year
"Day of Week: " + $a.DayOfWeek
"Day of Year: " + $a.DayOfYear
$Days = (New-TimeSpan -Start 1/1/1900 -End (Get-Date)).Days
$Weeks = [int]($Days / 7)
$SourceFolder = "C:\Users\Mark\Documents\reports"
$DestinationFolder1 = "\\x.x.x.x\lcms\$HN\Test2\$b"
$DestinationFolder2 = "\\x.x.x.x\lcms\$HN\Test3\$b"
IF ($a.DayOfWeek = "Day of Week: Sunday" -and $Weeks % 2 -eq 0)
{Robocopy $SourceFolder $DestinationFolder1 /S /R:3 /W:30 /XO}
ELSE
{Robocopy $SourceFolder $DestinationFolder1 /S /R:3 /W:30 /XO /MAXAGE:1}
IF ($a.DayOfWeek = "Day of Week: Sunday" -and $Weeks % 2 -ne 0)
{Robocopy $SourceFolder $DestinationFolder2 /S /R:3 /W:30 /XO}
ELSE
{Robocopy $SourceFolder $DestinationFolder2 /S /R:3 /W:30 /XO /MAXAGE:1}
*Error Text Below*
'DayOfWeek' is a ReadOnly property.At C:\Users\Mark\Desktop\Scripts\Lab Backup.PS1:15 char:5
+ IF ($a.DayOfWeek = "Day of Week: Sunday" -and $Weeks % 2 -eq 0)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
- Edited by Baiseley Friday, November 01, 2013 12:40 PM


