I have a script that uses Get-ChildItem like so:
$files = Get-ChildItem -Path $directories -Recurse -File -Include "package.json"
that works perfectly fine when run from ANY powershell prompt, EXCEPT when run from the task scheduler.
My task scheduler action is:
powershell -version 3.0 -noprofile -nolog -noninteractive -file somescript.ps1 someargs
From the task scheduler I get the error: a parameter cannot be found that matches parameter name 'file' for Get-ChildItem.
What I know:
- This error is usually caused because the 'File' attribute was not added until Powershell v3.0
- I am supposed to be able to force Powershell to run in version 3.0 using the
-version 3.0parameter. However, this doesn't appear to be making any difference from the task scheduler.
Any ideas regarding what I need to change?
-fileand adding this at the end:... | ? {!$_.psiscontainer}- Anthony Stringer-versionparameter for this. Either your version of PS supports the parameter or it doesn't, but in both cases downgrading the version can't help. - Ryan Bemrose-Fileisn't valid at all forGet-ChildItem.. not to mention, that switch doesn't have anything after it variable-wise except for another switch (-Include "package.json") - gravity