试图将变量用于move-item并收到错误:“无法绑定路径”

时间:2015-09-18 11:38:10

标签: powershell logging archiving

我正试图创建一个使用7zip压缩文件的脚本。 我已经完成了基本工作,但在尝试使其变得“更聪明”之后,我设法打破它并且无法弄清楚如何使新功能正常工作。

$filePath = "D:\Logs\test\201310\" #location to look in
$Archive = "D:\Logs\Test\201310\"
$Extension = "*.log" #extensions to look for
$Days = "30" #Number of days past today's date that will be archived
$CutDay = [DateTime]::Now.AddDays($Days)
$log = Get-ChildItem $filePath -include $Extension -recurse | Where-Object {$_.LastWriteTime -lt $CutDay}
$Archivename = (Get-Date).tostring("dd-MM-yyyy")
$archivepre = $archive.$Archivename
$Filepre = Get-ChildItem -Path $filePath | Where-Object {$_.LastWriteTime -le $CutDayday}
 foreach ($File in $log)
{
    write-host "File Name : $File " $File.LastWriteTime
}
    foreach ($File in $log)
{   
        if ($filepre -le $filePath)
            {
            mv $_.FullName $archivepre
            }
}
foreach ($file in $archivepre)
{
    $7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"
    $parameter = @('a', '-t7z', '-m0=PPMd',"$sourceFolder$Archivename", "$destinationfolder")
    &$7zipPath @parameter
    break
}

我遇到的问题是if语句中的mv无法绑定路径

"Move-Item : Cannot bind argument to parameter 'Path' because it is null.
At D:\Logs\test\7zip2.ps1:54 char:7
+                 mv <<<<  $_.FullName $archivepre
    + CategoryInfo          : InvalidData: (:) [Move-Item], ParameterBindingVa
   lidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
   icrosoft.PowerShell.Commands.MoveItemCommand

据我了解,我应该能够将MV设置为原样并且它仍然有用吗?

我希望脚本查看上次修改日期,并且仅在X天后压缩。

0 个答案:

没有答案