简体   繁体   中英

Invoking PowerShell through a command prompt does not allow the use of Pipe “|”

Invoking PowerShell through a command prompt does not allow the use of Pipe “|”. As a simple example, the following does not select “FullName”

C:>powershell -ExecutionPolicy RemoteSigned -noprofile -noninterac
tive Invoke-Command -Computer Remote.Computer -ScriptBlock { Import-Module
'C:\Scripts\RunVirtualMachineManager.ps1'; ls " | select FullName" }

I can't test this, but this looks better:

powershell -ExecutionPolicy RemoteSigned -noprofile -noninteractive "Invoke-Command -Computer Remote.Computer -ScriptBlock { Import-Module 'C:\Scripts\RunVirtualMachineManager.ps1'; ls | select FullName }"

Shouldn't the module you're trying to import end in .psm1?

For example, this works for me:

powershell -Executionpolicy RemoteSigned -noprofile -noninteractive "Get-Process | Select ProcessName"

The command you want to run, including the pipe, all goes inside quotes.

以下净化后的版本对我们有用(使用“选择计数”示例):C:> powershell -ExecutionPolicy RemoteSigned -noprofile -noninteractive“&{Invoke-Command -Computer Remote.Computer -ScriptBlock {导入模块'C:\\\\ .ps1'| Out-Null; |选择计数|格式列表}}“

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM