Get-Item

PS C:\scratch> Get-ChildItem .

    Directory: C:\scratch

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016-06-30     19:46                bar
d-----       2016-06-30     19:46                foo
d-----       2016-06-30     20:55                quux [123]

PS C:\scratch>

Ok.

PS C:\scratch> Get-ChildItem . | select -ExpandProperty name
bar
foo
quux [123]
PS C:\scratch>

Bra, bra...

PS C:\scratch> Get-ChildItem . | select -ExpandProperty name | Get-Item

    Directory: C:\scratch

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016-06-30     19:46                bar
d-----       2016-06-30     19:46                foo

PS C:\scratch>

Øh...

PS C:\scratch> Get-Item "quux [123]"
PS C:\scratch> "quux [123]" | Get-Item
PS C:\scratch>

Men i...

PS C:\scratch> Get-Item "foo"

    Directory: C:\scratch

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016-06-30     19:46                foo

PS C:\scratch> "foo" | Get-Item

    Directory: C:\scratch

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016-06-30     19:46                foo


PS C:\scratch>

Hmmm...
 
PS C:\scratch> Get-Help Get-Item -Parameter path

-Path <String[]>
    Specifies the path to an item. This cmdlet gets the item at the specified location. Wildcards are permitted. This parameter is required, but the parameter name ("Path") is optional.

    Use a dot (.) to specify the current location. Use the wildcard character (*) to specify all the items in the current location.

    Required?                    true
    Position?                    1
    Default value                none
    Accept pipeline input?       true (ByValue, ByPropertyName)
    Accept wildcard characters?  false


PS C:\scratch>

Heh...

Specifies the path to an item. This cmdlet gets the item at the specified location. Wildcards are permitted. [...]
[...]
Accept wildcard characters?  false

...

PS C:\scratch> "quux `[123`]" | Get-Item

PS C:\scratch> "quux ``[123``]" | Get-Item

    Directory: C:\scratch

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016-06-30     20:55                quux [123]

PS C:\scratch>

Grah!

PS C:\scratch> "*[1-3]*" | Get-Item

    Directory: C:\scratch

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016-06-30     20:55                quux [123]


PS C:\scratch> "*[au]*" | Get-Item

    Directory: C:\scratch

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016-06-30     19:46                bar
d-----       2016-06-30     20:55                quux [123]

PS C:\scratch>

Gaaaah!

PS C:\Users\gunnar> Get-Help Get-Item -Parameter literalpath

-LiteralPath <String[]>
    Specifies a path to the item. Unlike the Path parameter, the value of LiteralPath is used exactly as it is typed. N
    o characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation m
    arks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

    Required?                    true
    Position?                    named
    Default value                None
    Accept pipeline input?       true(ByPropertyName)
    Accept wildcard characters?  false

PS C:\scratch> Get-ChildItem . | select @{name='Literalpath';e={$_.name}} | Get-Item

    Directory: C:\scratch

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016-06-30     19:46                bar
d-----       2016-06-30     19:46                foo
d-----       2016-06-30     20:55                quux [123]

PS C:\scratch>

 

..|.,

 

 

Emneord: powerhell, powershell
Publisert 30. juni 2016 21:10 - Sist endret 2. juli 2016 13:12
Legg til kommentar

Logg inn for å kommentere

Ikke UiO- eller Feide-bruker?
Opprett en WebID-bruker for å kommentere