Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Why does this command not work?

Reply
 
Old 01-03-2007   #1 (permalink)
MadBison@gmail.com


 
 

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 SpecsSystem Spec
Old 01-03-2007   #2 (permalink)
RichS


 
 

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 SpecsSystem Spec
Old 01-03-2007   #3 (permalink)
Jacques Barathon [MS]


 
 

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 SpecsSystem Spec
Old 01-03-2007   #4 (permalink)
Sung M Kim


 
 

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 SpecsSystem Spec
Old 01-04-2007   #5 (permalink)
MadBison@gmail.com


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46