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
}

 

你可能感兴趣的:(Powershell-抛文档并捕获异常)