我有以下代码:
$items = Get-ChildItem -Path 'D:\Myoutput\'
$items | ForEach-Object
{
$lastWrite = ($_).LastWriteTime
$timespan = New-Timespan -days 3 -hours 0 -Minutes 0
if(((get-date) - $lastWrite) -gt $timespan) {
$name = $_.Name
$isDir = $_.PSIsContainer
if(!$isDir) {
$_ | Compress-Archive -DestinationPath "D:\Myoutput\Archive\$name.zip"
if (**above_line** is success) {
echo "$name is zipped"
$_ | Remove-Item
}
}
}
}
请帮忙,我怎样才能知道'$_ | Compress-Archive -DestinationPath "D:\Myoutput\Archive$name.zip"' 是否成功。