![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Why does this command not work? Hello Does anyone know what I am doing wrong here? Provider | foreach-object {$_.drives} | foreach-object {$a = $_.name + ":\"; & "dir $a"} I get the following message per provider. 'dir Alias:\' is not recognized as a cmdlet, function, operable program, or script file. At line:1 char:85 + get-psprovider | foreach-object {$_.drives} | foreach-object {$a = $_.name + ":\"; &" <<<< dir $a"} 'dir Env:\' is not recognized as a cmdlet, function, operable program, or script file. At line:1 char:85 + get-psprovider | foreach-object {$_.drives} | foreach-object {$a = $_.name + ":\"; &" <<<< dir $a"} Seems to me that "dir Env:\" does work if I type it in and execute it, but not if I make the command from the providers collection. Any help appreciated. Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Why does this command not work? This seemed to work for me Get-PSProvider | ForEach-Object{$_.drives} | ForEach-Object{$a = $_.name + ":\"; dir $a} I don't think you needed the & and " " around dir $a -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty "MadBison@gmail.com" wrote: > Hello > > Does anyone know what I am doing wrong here? > Provider | foreach-object {$_.drives} | foreach-object {$a = $_.name + > ":\"; & "dir $a"} > > I get the following message per provider. > > 'dir Alias:\' is not recognized as a cmdlet, function, operable > program, or script file. > At line:1 char:85 > + get-psprovider | foreach-object {$_.drives} | foreach-object {$a = > $_.name + ":\"; &" <<<< dir $a"} > 'dir Env:\' is not recognized as a cmdlet, function, operable program, > or script file. > At line:1 char:85 > + get-psprovider | foreach-object {$_.drives} | foreach-object {$a = > $_.name + ":\"; &" <<<< dir $a"} > > Seems to me that "dir Env:\" does work if I type it in and execute it, > but not if I make the command from the providers collection. > > Any help appreciated. > Thanks > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Why does this command not work? "RichS" <RichS@discussions.microsoft.com> wrote in message news:047CFB06-03F9-413E-B82B-87E40F88F59E@microsoft.com... > This seemed to work for me > > Get-PSProvider | ForEach-Object{$_.drives} | ForEach-Object{$a = $_.name + > ":\"; dir $a} > > I don't think you needed the & and " " around dir $a In addition, see the recent thread called "Execute a command in a string" for an explanation why & "dir $a" doesn't work. Jacques |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Why does this command not work? MadBison@gmail.com wrote: > Hello > > Does anyone know what I am doing wrong here? > Provider | foreach-object {$_.drives} | foreach-object {$a = $_.name + > ":\"; & "dir $a"} If you insist to use wrap "dir $a" with quotes, then you can invoke-expression the string as follows: get-psprovider | foreach-object {$_.drives} | foreach-object {$a = $_.name + ":\"; invoke-expression "dir $a"} But as Jacques Barathon mentioned, there is no need for "&" or "invoke-expression" just call "dir $a" without double quotes around it. get-psprovider | foreach-object {$_.drives} | foreach-object {$a = $_.name + ":\"; dir $a} |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Why does this command not work? Thanks everyone for your help. Indeed, removing the & and quotes did the trick. Get-PSProvider | foreach-object {$_.drives}| foreach-object {$a = $_.name + ":\"; dir $a} Thanks Sung M Kim wrote: > MadBison@gmail.com wrote: > > Hello > > > > Does anyone know what I am doing wrong here? > > Provider | foreach-object {$_.drives} | foreach-object {$a = $_.name + > > ":\"; & "dir $a"} > > If you insist to use wrap "dir $a" with quotes, then you can > invoke-expression the string as follows: > > get-psprovider | foreach-object {$_.drives} | foreach-object {$a = > $_.name + ":\"; invoke-expression "dir $a"} > > But as Jacques Barathon mentioned, there is no need for "&" or > "invoke-expression" just call "dir $a" without double quotes around > it. > > get-psprovider | foreach-object {$_.drives} | foreach-object {$a = > $_.name + ":\"; dir $a} |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| I cannot get the console command in fallout 3 to work | Gaming | |||
| Re: My command promt deosnt work | Vista General | |||
| Route command doesn't work | Vista networking & sharing | |||
| Route command doesn't work | Vista networking & sharing | |||
| Route command doesn't work | Vista networking & sharing | |||