question

KyotoTasori-6918 avatar image
0 Votes"
KyotoTasori-6918 asked KyotoTasori-6918 commented

While loop cuases argumental errors with cmdlets Powershell

I was attempting to make a while loop for a input box and have it process it through another file though I keep getting a error that on another line it thinks its a positional argument


while ($true) {
$shell = Read-Host -Prompt "<"
Invoke-Command -ScriptBlock ([scriptblock]::Create((Get-Content ".\rescources\entry\Basehandler.ps1"))) -ArgumentList '$shell'
}


Error:

Read-Host : A positional parameter cannot be found that accepts argument 'Invoke-Command'.
At line:1 char:30
+ ... $shell = Read-Host -Prompt "<" Invoke-Command -ScriptBlock ([s ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Read-Host], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.ReadHostCommand

windows-serverwindows-server-powershellwindows-11
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
1 Vote"
MotoX80 answered KyotoTasori-6918 commented

At line:1 char:30

You don't have any new line characters to separate the lines. Everything is on one line, so you need to separate cmdlets with a semicolon.

 while ($true) {$shell = Read-Host -Prompt "<";  Write-Host "You entered $shell"} 

Personally, I like to put commands on separate lines to make it easier to read.

 while ($true) {
     $shell = Read-Host -Prompt "<"
     Write-Host "You entered $shell"
 }



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Omg Thank you so much also I like sperate lines aswell single line hurts my eyes.

0 Votes 0 ·