是否可以将PowerShell命令行拆分为多行?
在Visual Basic中,我可以在下一行中使用下划线(_)来继续命令。
是否可以将PowerShell命令行拆分为多行?
在Visual Basic中,我可以在下一行中使用下划线(_)来继续命令。
当前回答
我假设您谈论的是命令行——如果是在脚本中,那么new-line充当命令分隔符。
在命令行中,使用分号';'
其他回答
使用分号;分开命令 在任何反斜杠上替换双反斜杠\\。 使用“'传递安全地址到交换机命令,如“'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"
$scriptBlock = [Scriptblock]::Create(@'
echo 'before'
ipconfig /all
echo 'after'
'@)
Invoke-Command -ComputerName AD01 -ScriptBlock $scriptBlock
源 不要使用反引号
我开始的时候
if ($true) {
"you can write multiple lines here, and the command doesn't run untill you close the bracket"
"like this"
}
最近我发现我可以
&{
get-date
"more stuff"
}
我刚刚发现,在后勾号和换行符之间一定没有任何字符。即使是空格也会导致命令不起作用。
在多行中使用'字符分隔命令