1

I have seen many similar questions but none of them is related to the execution of a CMD command such as ipconfig from a PS script (.ps1).

If you type those commands on the PS console they work fine but once on a script they don't, below you can see an example:

PS C:\Users\TestQro> adb devices
List of devices attached

PS C:\Users\TestQro> adb devices | Select-String -Quiet List
True

returns True because the Select-String finds the word "List" in the response of the command "adb devices" which is the expected behavior. But if I go and put the same command into a .ps1 script file PS answers when running:

PS C:\TesterInfo> ./TunnerApp.ps1

cmdlet Write-Output at command pipeline position 1
Supply values for the following parameters: InputObject[0]:

How should I type the normal CMD commands inside of a script? Why is it waiting for parameters on script but right in the console it works fine?

3
  • For help with code that isn't working: show the code that isn't working. Commented Oct 4, 2018 at 7:51
  • Hi, thanks for helping out. The code is only this line: "adb devices | select-string -Quiet List" Commented Oct 4, 2018 at 13:21
  • Then please try starting a clean PowerShell instance from a CMD window (powershell.exe -NoExit -NoProfile) and run the script from there. Do you still get the same prompt? Commented Oct 4, 2018 at 13:54

2 Answers 2

2

Based on your output there

PS C:\TesterInfo> ./TunnerApp.ps1

cmdlet Write-Output at command pipeline position 1
Supply values for the following parameters: InputObject[0]:

It looks like you have a Write-Output statement somewhere in your PowerShell script that does not have any input. Look for an empty Write-Output statement somewhere

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, Thanks for helping out but the only line in the script is the same you see in the console so I don't know why the parameter is needed in the script and not when typed: adb devices | select-string -Quiet List
@JorgeAlbertoDiaz I see, maybe try piping out the adb devices to a file and grab the output of that and search for your value. adb devices > C:\temp\adb.txt $devices = Get-Content C:\temp\adb.txt
0

What you're referring to as CMD commands are actually executables in the Windows or System32 folders (or some other PATH environment variable path). As such, you can call them like you would any executable using the call operator:

& "$Env:SystemRoot\System32\IPCONFIG.exe"

about_Operators

1 Comment

External commands can be invoked as bare words without using the call operator as long as there is no space in the filename or path. ipconfig, & ipconfig, and & "ipconfig" should all do the same.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.