Windows Powershell 执行结束 返回状态码

前言全局说明

Windows Powershell 执行结束 返回状态码


一、

1.源码

用于将文件复制到文件夹的Powershell脚本

$dest ="C: est"
New-Item $dest -type directory -force
$source ="c:samplefile.txt"
Copy-Item $source $dest
exit $LASTEXITCODE

$LASTEXITCODE保存Powershell脚本中的最后一个错误代码。
它是布尔值的形式,0表示成功,1表示失败。
Exit<custom error codes>将从脚本中返回自定义返回状态码。



免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。




参考、来源:
https://www.manageengine.cn/products/desktop-central/returning-error-code-on-scripts-how-to.html



posted @ 2024-01-31 14:45  悟透  阅读(191)  评论(0)    收藏  举报