Powershell-抛文档并捕获异常

Posted jinweichang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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-抛文档并捕获异常的主要内容,如果未能解决你的问题,请参考以下文章