0
我不確定發生了什麼。我對Power Shell很新。 我有一個文件夾結構,其中包含圖像。我正在尋找所有X天的圖像,並將這些圖像複製到另外兩個位置。我得到的錯誤是:Copy-Item:無法將參數綁定到參數'Path',因爲它爲空
Copy-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\Documents and Settings\Administrator.VDICORP\Desktop\ProcessOSImages.ps1:37 char:24
+ copy-item -path <<<< $TheImage -destination $TestSite
+ CategoryInfo : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CopyItemCommand
我的代碼如下:
$TodaysDate = get-date
$FileAgeInDays = "-2"
$ImageLocation = "\\vdifiles\Print-Room\FileSrv\Barcode-Order"
$TestSite = "\\10.0.100.3\www2.varietydistributors.com\catalog\newpictures"
$LiveSite = "\\10.0.100.3\Variety Distributors.com\catalog\newpictures"
$WhenFileWritten = $TodaysDate.AddDays($FileAgeInDays)
$IncludeFileTypes = "*.jpeg,*.jpg"
$ExcludeFileTypes = "*.psd,*.tif,*.pdf"
$LogFile = "C:\Temp\FilesCopied.log"
$EmailServer = "mx1.domain.com"
$EmailFrom = "[email protected]"
$AuthUser = "user"
$AuthPass = "pass"
$XHeaderInfo = "X-Header: This email was sent from Laservault."
$EmailTo = "[email protected]"
$EmailSubject = "Barcode Images Summary."
$EmailBodySent = "TEST Attached to this email is a log file of what images were copied from $ImageLocation to $TestSite and $LiveSite as well as sent to AS2 to send over to Order Stream."
$EmailBodyNotSent = "TEST There were no files in $ImageLocation that matched $WhenFileWritten days old. So, nothing was sent to $TestSite, $LiveSite or AS2."
$TheImages = get-childitem $ImageLocation -include $IncludeFileTypes -exclude $ExcludeFileTypes -recurse -force | where-object {$_.CreationTime -le "$WhenFileWritten" -and $_.PsIsContainer -ne $true}
foreach ($TheImages in $TheImage) {
$FileCount = ($TheImage).count
if (!($FileCount -eq 0)) {
copy-item -path $TheImage -destination $TestSite
copy-item -path $TheImage -destination $LiveSite
write-host $FilesCount "images were copied."
write-output $TheImage >> $LogFile
\\vdifiles\blat$\blat.exe -attach $LogFile -to $EmailTo -s $EmailSubject -i $EmailFrom -body $EmailBodySent -server $EmailServer -u $AuthUser -pw $AuthPass -f $EmailFrom -x $XHeaderInfo
remove-item $LogFile
} else {
\\vdifiles\blat$\blat.exe -to $EmailTo -s $EmailSubject -i $EmailFrom -body $EmailBodyNotSent -server $EmailServer -u $AuthUser -pw $AuthPass -f $EmailFrom -x $XHeaderInfo
}
}
我要去哪裏錯了?
不應該在foreach循環開始是這樣的:'的foreach( $ TheImage in $ TheImages)'? – iCodez