Can anyone explain to me why I can write 'ECHO Y|' in the Powershell command line but not if I implement it in a script?

These variables are taken from a .csv file. When I used the command line I did not use the variables.

```
ECHO Y|cacls $_."Serverdisc" /G ADMINISTRATORS:F
 cacls $_."Serverdisc" /G $_."Username":C /T /E
 cacls $_."Serverdisc" /G SYSTEM:F /T /E

```
['https://Stackoverflow.com/questions/20402662', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2564636/']
I am guessing you are trying to pass "Y(es)" to any possible prompts?
CMD shell and PowerShell are two different shells. What you are trying to do is use the CMD shell syntax for Powershell and therefore running into trouble

$\_ is used when you are iterating through an array coming from pipeline, so there must be something other than what you have shared here. I will give you an example.

Assume I have 2 files in c:\temp\:

```
c:\temp\a.txt
c:\temp\b.txt

```

and I want to grant them permissions and not to be prompted.

```
"c:\temp\a.txt","c:\temp\b.txt" | foreach-object {
ECHO Y|cacls $_ /G ADMINISTRATORS:F
echo Y|cacls $_ /G SYSTEM:F /T /E
}

```

This is equivalent to the following

```
ECHO Y|cacls c:\temp\a.txt /G ADMINISTRATORS:F
echo Y|cacls c:\temp\a.txt /G SYSTEM:F /T /E
ECHO Y|cacls c:\temp\b.txt /G ADMINISTRATORS:F
echo Y|cacls c:\temp\b.txt /G SYSTEM:F /T /E

```

$\_ is being replaced withing foreach-object by what is coming down from pipeline, which is pretty much imitating CMD shell command that would work.
It's probably because the pipeline function of powershell is different from the cmd prompt

If you use `cmd /c echo Y| cacls ....`
it will work.