When using powershell, sometimes I want to only display for example the name or fullname of a file.
From what I can gather, the way to do this is by using Get-ItemProperty (alias of gp) and passing -n fullname, For example
PS C:\Dev> gp . -n fullname
Notably I want to use this in longer scripts combined with foreach and where, and so on
Powershell then displays the fullname, but it also displays a bunch of other stuff, as follows:
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 only display the property I want (fullname) and not cruft the display up with all the other stuff. Is Get-ItemProperty even the right way to do this?
Update:
If I do this:
ls -r | ?{ $_.fullname -match "foo" }
This gives me a series of lists, one for each directory, showing all the ‘foo’ files in each directory. What I’d like to do is consolidate those multiple lists into one single list, and not show the Mode, LastWriteTime, Length or any other irrelevant stuff. If Get-ItemProperty is not the correct way to show those things, what is?
There are many ways. I think you were looking for Get-ChildItem:
PS > get-childitem x.txt | select fullname
You could use Get-ItemProperty, but I think it’s more for things like registries.
Format-Table, alias ft is also good to know about…
Commonly used aliases for Get-ChildItem, are ls, dir, and gci. I’d go with gci, when in Rome.