I would like to run a Powershell script via the SQL Server Agent. This script works fine if I run it manually through the command prompt, but the job history in SQL Server Management Studio tells me a syntax error on line 8.
Is there a difference in the SQL Server Agent runtime environment?
Here is my script:
$ArchivesMPath = "E:\ArchivesBDD\Mensuelles"
$SauvegardeMPath = "E:\SauvegardeBDD\Mensuelle"
$ArchivesQPath = "E:\ArchivesBDD\Quotidiennes"
$SauvegardeQPath = "E:\SauvegardeBDD\Quotidienne"
$DAYSOFWEEK = "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"
$MONTHS = "Decembre", "Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre"
$DAILYDIR = "$ArchivesQPath\$($DAYSOFWEEK[(get-date).AddDays(-1).DayOfWeek.value__])"
if ([System.IO.Directory]::Exists($DAILYDIR)){
Remove-Item $DAILYDIR -Force -Recurse
}
New-Item -Path $DAILYDIR -ItemType directory
Move-Item -Path "$SauvegardeQPath\*" -Destination $DAILYDIR
if ((get-date).AddDays(-1).day -eq 1){
$MONTHLYDIR = "$ArchivesMPath\$($MONTHS[(get-date).month])"
if ([System.IO.Directory]::Exists($MONTHLYDIR)){
Remove-Item $MONTHLYDIR -Force -Recurse
}
New-Item -Path $MONTHLYDIR -ItemType directory
Move-Item -Path "$SauvegardeMPath\*" -Destination $MONTHLYDIR
}
Thank you in advance for your help