是否可以将PowerShell命令行拆分为多行?
在Visual Basic中,我可以在下一行中使用下划线(_)来继续命令。
是否可以将PowerShell命令行拆分为多行?
在Visual Basic中,我可以在下一行中使用下划线(_)来继续命令。
当前回答
使用分号;分开命令 在任何反斜杠上替换双反斜杠\\。 使用“'传递安全地址到交换机命令,如“'PATH'”。
这个ps1命令安装地区pfx证书。
powershell -Command "$pfxPassword = ConvertTo-SecureString -String "12345678" -Force -AsPlainText ; Import-PfxCertificate -FilePath "'C:\\Program Files\\VpnManagement\\resources\\assets\\cert\\localhost.pfx'" Cert:\\LocalMachine\\My -Password $pfxPassword ; Import-PfxCertificate -FilePath "'C:\\Program Files\\VpnManagement\\resources\\assets\\cert\\localhost.pfx'" Cert:\\LocalMachine\\Root -Password $pfxPassword"
其他回答
扩展一下克里斯托巴利托的回答:
我假设您谈论的是命令行——如果是在脚本中,那么新行>充当命令分隔符。 在命令行中,使用分号';'
例如:
在命令行上签署PowerShell脚本。没有换行。
powershell -Command "&{$cert=Get-ChildItem –Path cert:\CurrentUser\my -codeSigningCert ; Set-AuthenticodeSignature -filepath Z:\test.ps1 -Cert $cert}
在PowerShell和PowerShell ISE中,也可以在每行末尾使用Shift + Enter进行多行编辑(而不是标准的反引号')。
在多行中使用'字符分隔命令
在windows终端(powershell配置文件),我可以简单地单击Shift-Enter对我来说很好。
PS C:\xxx2021> Get-ChildItem -Include *remote* -Recurse |
>> Sort-Object -Property LastWriteTime -Descending |
>> Select-Object LastWriteTime, Name -First 25
LastWriteTime Name
------------- ----
12/5/2021 5:04:02 PM remote-control-car-BatteryPack-Number-2021-12-03.pdf
PS C:\xxx2021>enter code here
只要在这里加上一个极端情况。这可能会帮你节省5分钟。如果你使用一连串的动作,你需要在行末加上“。”,然后在“'”后面留下一个空格(反勾号)。这是我很不容易才发现的。
$yourString = "HELLO world! POWERSHELL!". `
Replace("HELLO", "Hello"). `
Replace("POWERSHELL", "Powershell")