How can I make Windows Powershell Get-ItemProperty show only the property I want?

When using powershell, sometimes I want to display, for example, the name or full name of the file.
From what I can assemble, the way to do this is to use Get-ItemProperty(an alias gp) and pass -n fullname, for example

PS C:\Dev> gp . -n fullname

In particular, I want to use this in longer scripts in conjunction with foreach, and whereetc.

Powershell then displays the full name, but also displays a bunch of other things, as shown below:

PSPath       : Microsoft.PowerShell.Core\FileSystem::C:\Dev
PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\
PSChildName  : Dev
PSDrive      : C
PSProvider   : Microsoft.PowerShell.Core\FileSystem
fullname     : C:\Dev

My question is: how can I get powershell to display only the property that I want (full name) and not rotate the display with all other things. Is the Get-ItemPropertyright way?

Update:

If I do this:

ls -r | ?{ $_.fullname -match "foo" }

, , "foo" . Mode, LastWriteTime, Length . Get-ItemProperty , ?

+3
5

. , Get-ChildItem:

PS > get-childitem x.txt |

    FullName
    --------
    C:\WINDOWS\system32\WindowsPowerShell\v1.0\x.txt


    PS > get-childitem x.txt | select name

    Name
    ----
    x.txt


    PS > get-childitem x.txt | % { $_.fullname }
    C:\WINDOWS\system32\WindowsPowerShell\v1.0\x.txt
    PS >

Get-ItemProperty, , , .

PS > Get-ItemProperty x.txt | select name

Name
----
x.txt

-, ft ...

PS > gci x.txt | format-table -a fullname,length

FullName                                         Length
--------                                         ------
C:\WINDOWS\system32\WindowsPowerShell\v1.0\x.txt    126

Get-ChildItem - ls, dir gci. gci, .

+8

( , ):

(gi c:\temp\file -ea 0).fullname

(gi c:\temp\file -ea 0) | select -ExpandProperty fullname

C:\Temp\

-ea: ,

+3

... PowerShell (ETS).

Update-TypeData.

...

+2

foreach, , - , .

foreach ($file in dir)
{
  $file.fullname
}
+1

Get-ItemProperty , , Get-Item get-ChildItem.

ls hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
gp hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

, ,

ls | ? { $_.FullName -match "whatever"}
0
source

All Articles