【发布时间】:2018-11-26 17:50:53
【问题描述】:
我正在尝试将带有参数的 PowerShell 脚本作为计划任务执行。在启动程序屏幕上我有
程序/脚本
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
并在添加参数
-Command "& C:\Test\MoveFiles.ps1 -destinationRoot \\OB-VM-ME-Data\ME-Data\Archived\Test"
我做错了什么?
编辑:附件是有问题的脚本
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
}
【问题讨论】:
标签: powershell