# Powershell what-if
# 试运行:模拟操作
# 通过-whatif 参数。事实上,许多cmdltes都支持试运行
#如果执行stop-process -name *a*会终止下面的进程。
# Stop-Process -Name *a* -WhatIf
# 想让自己的脚本和函数也支持模拟运行,只需要进行简单的整合。多增加一个switch参数
# function MapDrive([string]$driveletter,[string]$target,[switch]$whatif)
# {
# if($whatif)
# {
# Write-Host "WhatIf: creation of a network drive " + "with the letter ${driveletter}: at destination $target"
# }
# else
# {
# New-PSDrive $driveletter FileSystem $target
# }
#
# }
# 为了防止产生失误操作,可以逐个进行确认,-Confirm逐个进行放行。
# Stop-Process -Name *cm* -Confirm
# 自动对危险的操作进行操作--
# Powershell 定义容错度
# 自动化变量$ErrorView的默认值为:NormalView,如果将$ErrorView设置为categoryview 异常就会只显示一行
# $ErrorView
# Remove-Item mossfly.com ;
# Write-Host "工作完成"
# Powershell在执行某条命令是也可以指定对错误的处理模式。那就是ErrorAction。
# del "no this file" -ErrorAction Continue;
# Write-Host "工作完成"
# 如果将ErrorAction的值设置为Silently
Powershell错误处理
最新推荐文章于 2023-05-16 14:11:18 发布