I am trying to execute a PowerShell script with parameters as a scheduled task. On the Start a program screen I have
Program/script
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
and in Add arguments
-Command "& C:\Test\MoveFiles.ps1 -destinationRoot \\OB-VM-ME-Data\ME-Data\Archived\Test"
What am I doing incorrectly?
EDIT: Attached is the script in question
Param (
[Parameter(Mandatory=$true)][string]$destinationRoot
)
$path = (Get-Item -Path ".\").FullName
Get-ChildItem $path\* -Include *.bmp, *.svg | Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-30)
} | ForEach-Object {
$content = $path + "\" + $_.Name
$year = (Get-Item $content).LastWriteTime.Year.ToString()
$monthNumber = (Get-Item $content).LastWriteTime.Month
$month = (Get-Culture).DateTimeFormat.GetMonthName($monthNumber)
$destination = $destinationRoot + "\" + $year + "\" + $month
New-Item -ItemType Directory -Force -Path $destination
Move-Item -Path $content -Destination $destination -Force
}