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
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\:
and I want to grant them permissions and not to be prompted.
This is equivalent to the following
$_ is being replaced withing foreach-object by what is coming down from pipeline, which is pretty much imitating CMD shell command that would work.