我正在尝试根据文件名将文件名中的特殊字符删除到某个目的地后移动所有邮件。FOLDLIST 是一个数组,其中我有条件变量和目标文件夹名称。
Set-Location 'C:\Users\abrahame\Desktop\Work\PSG Mail Movement\Mail'
$DESLOC="c:\Temp\ua-closed bugs"
$FOLDLIST = @(("UA", "CLOSE", "ua-closed bugs"), ("VS", "CLOSE", "vs-closed-bugs"), ("CM", "CLOSED", "cm - closed-bugs"))
gci | Foreach-object { $NEWN = $_.Name -replace '&',' ' -replace '_', ' ' -replace '#', ' ' -replace '!', ' ' -replace '@', ' ' -replace '$', ' ' -replace '%', ' ' -replace '^', ' ' -replace '&', ' ' -replace '\(', ' ' -replace '\)', ' ' -replace '\[', ' ' -replace '\]', ' ' -replace '\{', ' ' -replace '\}', ' ' -replace '\-', ' ';
write-host $NEWN.Length
if($NEWN.Length -gt 70){
$NEWN="$NEWN.Substring(1,70)"
$NEWN=$NEWN.msg
}
$FOLDLIST | ForEach-Object {
$CXR=$_[0]
$STAT=$_[1]
if ($NEWN -match ("$CXR") -and $NEWN -match ("$STAT")){
write-host $CXR - $STAT
$DIR=$_[2]
$NEWN=$NEWN.trim()
$DPATH="$DESLOC\$DIR\$NEWN"
write-host $DPATH
mv $_.Name $DPATH
}
}
}
我收到这个错误。请告知我在哪里做错了..
67
UA - CLOSE
c:\Temp\ua-closed bugs\ua-closed bugs\RE CLOSE OA TICKET 10350 OA UAT PHASE FOR HP FARES 1 .msg
Move-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\Users\abrahame\Desktop\Work\PSG Mail Movement\mailmove_multdimentional.ps1:24 char:5
+ mv <<<< $_.Name $DPATH
+ CategoryInfo : InvalidData: (:) [Move-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.MoveItemCom
mand