Windows Vista Forums
Vista Forums Home Join Vista Forums Donate 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

What is the syntax for piping LiteralPath to Get-ChildItem

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 10-05-2007   #1 (permalink)
Bob Landau
Guest


 

What is the syntax for piping LiteralPath to Get-ChildItem

According to the help this does accept pipeline input as long as it's by name.

However I've tried the either of these and had no success.

'-LiteralPath c:\' | GetChildItem

or a more complex expression

'-LiteralPath "C:\Program Files"' | GetChildItem

In each case the results are the same. Get-ChildItem reports the error that
it can't find the drive specified in the pipe.

thx
bob

(output from trace-object)

......

DEBUG: ParameterBinding Information: 0 : BIND PIPELINE object to parameters:
[Get-ChildItem]
DEBUG: ParameterBinding Information: 0 : PIPELINE object TYPE =
[System.String]
DEBUG: ParameterBinding Information: 0 : RESTORING pipeline parameter's
original values
DEBUG: ParameterBinding Information: 0 : Parameter [Path] PIPELINE INPUT
ValueFromPipeline NO COERCION
DEBUG: ParameterBinding Information: 0 : BIND arg [-literalpath 'c:\']
to parameter [Path]

.....

Get-ChildItem : Cannot find drive. A drive with name '-literalpath 'c' does
not exist.
At line:1 char:84
+ trace-command -name parameterbinding,cmdlet -expression {"-literalpath
'c:\'" | gci} <<<< -pshost

My System SpecsSystem Spec
Old 10-05-2007   #2 (permalink)
Jeff
Guest


 

Re: What is the syntax for piping LiteralPath to Get-ChildItem

On Oct 6, 4:59 am, Bob Landau <BobLan...@xxxxxx>
wrote:
Quote:

> According to the help this does accept pipeline input as long as it's by name.
>
The LiteralPath parameter accepts pipeline input, but only by property
name. This means that the object on the pipeline has to have a
property named LiteralPath in order for Get-ChildItem's LiteralPath
parameter to be filled. The object you are sending it is just a
string, so it doesn't have this information. Contrast this with Get-
ChildItem's Path parameter, which can also take input by value. This
is why the following will work:

"C:\Program Files" | Get-ChildItem

Jeff

My System SpecsSystem Spec
Old 10-05-2007   #3 (permalink)
Kiron
Guest


 

Re: What is the syntax for piping LiteralPath to Get-ChildItem

Complementing Jeff's answer with a sample:

ByPropertyName means that the piped object must have a property name equal to the Cmdlet's parameter.

# create a new dir whose name contains brackets, as you know
# get-childItem's -path parameter will not 'get' these items,
# need to use -literalPath
new-item c:\ -name test[1] -type directory

# create a few child items in it
0..4 | % {new-item c:\test``[1``] -n file$_.txt -t file}

# no results
get-childItem C:\test[1]

# eventhough they do exist
get-childItem -literalPath C:\test[1]

# # # # # # # # # # # # # # # # # #
# -< obj.csv >-
# Name,LiteralPath
# "test[1]","C:\test[1]"
# "Program Files","C:\Program Files"
# -< obj.csv >-
# # # # # # # # # # # # # # # # # #

# create an object from a CSV file that contains
# a field named LiteralPath
$obj = import-csv obj.csv

# get-childItem takes that value byPropertyName
# when the object is piped to it
$obj | get-childItem

# remove test dir and its children
remove-item -literalPath C:\test[1] -recurse

--
Kiron
My System SpecsSystem Spec
Old 10-05-2007   #4 (permalink)
Bob Landau
Guest


 

Re: What is the syntax for piping LiteralPath to Get-ChildItem


This does make sense (like most things in hindsight)

Unfortunately it does make it more difficult to construct ad-hoc pipe
parameters

Regardless you explaination is Much Appreciated.

thx
bob

"Jeff" wrote:
Quote:

> On Oct 6, 4:59 am, Bob Landau <BobLan...@xxxxxx>
> wrote:
Quote:

> > According to the help this does accept pipeline input as long as it's by name.
> >
>
> The LiteralPath parameter accepts pipeline input, but only by property
> name. This means that the object on the pipeline has to have a
> property named LiteralPath in order for Get-ChildItem's LiteralPath
> parameter to be filled. The object you are sending it is just a
> string, so it doesn't have this information. Contrast this with Get-
> ChildItem's Path parameter, which can also take input by value. This
> is why the following will work:
>
> "C:\Program Files" | Get-ChildItem
>
> Jeff
>
>
My System SpecsSystem Spec
Old 10-05-2007   #5 (permalink)
Bob Landau
Guest


 

Re: What is the syntax for piping LiteralPath to Get-ChildItem

Thank you Kiron,

Both you and Jeff have help me understand this better. I know need to take
your exampe and work with it

bob

"Kiron" wrote:
Quote:

> Complementing Jeff's answer with a sample:
>
> ByPropertyName means that the piped object must have a property name equal
> to the Cmdlet's parameter.
>
> # create a new dir whose name contains brackets, as you know
> # get-childItem's -path parameter will not 'get' these items,
> # need to use -literalPath
> new-item c:\ -name test[1] -type directory
>
> # create a few child items in it
> 0..4 | % {new-item c:\test``[1``] -n file$_.txt -t file}
>
> # no results
> get-childItem C:\test[1]
>
> # eventhough they do exist
> get-childItem -literalPath C:\test[1]
>
> # # # # # # # # # # # # # # # # # #
> # -< obj.csv >-
> # Name,LiteralPath
> # "test[1]","C:\test[1]"
> # "Program Files","C:\Program Files"
> # -< obj.csv >-
> # # # # # # # # # # # # # # # # # #
>
> # create an object from a CSV file that contains
> # a field named LiteralPath
> $obj = import-csv obj.csv
>
> # get-childItem takes that value byPropertyName
> # when the object is piped to it
> $obj | get-childItem
>
> # remove test dir and its children
> remove-item -literalPath C:\test[1] -recurse
>
> --
> Kiron
>
My System SpecsSystem Spec
Old 10-05-2007   #6 (permalink)
Kiron
Guest


 

Re: What is the syntax for piping LiteralPath to Get-ChildItem

Glad to help Bob.
I used export-csv to create the object in the sample, but you could also create a LiteralPath property for DirectoryInfo and FileInfo objects through PowerShell's ETS or add a member to a live object with add-member. Also, to save and later retrieve custom objects you can use export-csv, export-cliXml and import-csv, import-cliXml respectively.

--
Kiron
My System SpecsSystem Spec
Old 10-05-2007   #7 (permalink)
Kiron
Guest


 

Re: What is the syntax for piping LiteralPath to Get-ChildItem

Excuse the mistake:
I used import-csv ...

--
Kiron
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
bug: get-acl, rename-item missing the LiteralPath parameter Hal Rottenberg PowerShell 0 06-29-2008 05:45 PM
One more question on -LiteralPath and -Include/-Exclude for GetChi Bob Landau PowerShell 4 10-08-2007 01:31 PM
-LiteralPath is a less than optimal solution Keith Hill [MVP] PowerShell 9 05-12-2007 12:57 AM
All about piping Marco Shaw PowerShell 2 11-20-2006 11:20 AM
New to ps object piping Adam Murray PowerShell 2 09-14-2006 02:14 AM


Update your Vista Drivers Update Your Drivers Now!!

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