Powershell-抛文档并捕获异常

#source1 file location
$source1 = "C:\users\me\desktop\test1"

#dest1 file location
$dest1 = "C:\users\me\desktop\final\"

#finds files in $source1 that are the very latest and copies to $dest1
try {
Get-ChildItem $source1 -Recurse | Sort-Object -Property CreationTime -Descending | Select-Object -First 1 | Copy-Item -Destination $dest1 -ErrorAction 'Stop'
}
catch{
    $_.Exception.Message | Out-File -FilePath .\errorlog.txt -Encoding utf8
}

猜你喜欢

转载自www.cnblogs.com/JinweiChang/p/11400647.html