Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Why does this command not work?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-03-2007   #1 (permalink)
MadBison@gmail.com
Guest


 

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
Guest


 

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]
Guest


 

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
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: My command promt deosnt work GTS Vista General 1 04-26-2008 02:08 AM
MSMAPI32 FETCH COMMAND DON'T NOT WORK IN WINDOWS MAIL ! Alex Vista mail 0 03-01-2007 11:46 AM
Route command doesn't work Luca Vista networking & sharing 0 06-14-2006 07:31 AM
Route command doesn't work Luca Vista networking & sharing 0 06-14-2006 06:32 AM
Route command doesn't work Luca Vista networking & sharing 0 06-14-2006 06:31 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51