Powershell 如何像 Linux shell 的 && 一样


PowerShell交流中心分类: 变量-函数-脚本-条件-循环-参数Powershell 如何像 Linux shell 的 && 一样
0
Net asked 5 年 ago
PS C:\Windows\system32> Get-Acls ; Get-Host
Get-Acls : 无法将“Get-Acls”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ Get-Acls ; Get-Host
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Acls:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 


Name             : Windows PowerShell ISE Host
Version          : 4.0
InstanceId       : 4faa18f0-e362-40f8-9c81-f353414623b7
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : zh-CN
CurrentUICulture : zh-CN
PrivateData      : Microsoft.PowerShell.Host.ISE.ISEOptions
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Powershell 如何像 Linux shell 的 && 一样,前面命令执行成功则执行后面语句,如果前面命令执行错误,则退出后面语句

1 Answers
1
Best Answer
神经元短路 answered 5 年 ago
try{Get-Acls Get-Host} catch{$error[0];break}