2

I am trying to see full key names in registry because I want to copy them to a text file later but I can't see the full name. So first I enter to the registry hive I need:
cd HKLM:
cd SOFTWARE\Microsoft\Windows\CurrentVersion\ModuleUsage

And now I run: Get-ChildItem | format-table name But this is what I received: enter image description here

I tried to copy it to text file thought maybe it doesn't show it full because of the GUI but it didn't help. So I tried to replace 'Format-Table' with 'Format-List' and it show me the full name: enter image description here

But now I need to run some functions to cut the 'Name : ' off which shouldn't be a problem but I wonder if it possible to show me the full name with 'Format-Table'

Thanks

E235
  • 11,560
  • 24
  • 91
  • 141
  • Please take a step back and describe the actual problem you're trying to solve instead of what you perceive as the solution. `Format-Table` and `Format-List` are cmdlets for presenting data in a particular format. Do **not** use them if you need to further process the data. – Ansgar Wiechers Mar 09 '14 at 15:22
  • I needed to create script in batch file that the deletes some registry keys and but there were too many keys to copy so I wanted to export all the keys another some folder in the Hive. – E235 Mar 09 '14 at 16:25

2 Answers2

3

Format-* commands are built to format things for your viewing pleasure. They are not meant to pass usable objects along the pipeline - if you try to do anything with the results of a Format-* command, apart from sending it to Out-* commands like Out-String or Out-File, you will get gibberish.

Use Select-Object.

#View an array of strings (from name property)
Get-ChildItem | Select-Object -ExpandProperty name

#Write these strings to a file
Get-ChildItem | Select-Object -ExpandProperty name | Set-Content C:\temp\test.txt

In general, you should avoid the Format-* commands unless you have a specific goal in mind. For example, using them with Write-Verbose or with ShouldProcess messages for clarity. Just keep in mind you lose any ability to work with the data as objects once you use Format-*.

Cheers!

Cookie Monster
  • 1,741
  • 1
  • 19
  • 24
1

You can use -Wrap switch of Format-Table. It specifies that text that exceeds the column width was moved on the next line. By default, text that exceeds the column width is truncated.

Get-ChildItem | Format-Table Name -Wrap
  • @levgen It works but not perfect. when I export it to TXT file it creates the key name in two rows. I wonder if I can force it to use one row ? – E235 Mar 09 '14 at 12:43
  • If I change the Width of powershell window from 120 to 300 it saves the full name in one row which is good to me. But if I need to run some script on some computer and the key is more than the width of the powershell window it will create it as two rows in the text file. Maybe there is command that stretch the each string only on one line – E235 Mar 09 '14 at 13:28
  • @e235 see https://stackoverflow.com/questions/24218482/whats-the-maximum-number-of-columns-for-format-table-cmdlet-in-powershell/38794195#comment65357979_38794195 when redirecting to a text file, use `Out-File -FilePath filename.txt -Width 500` as `Format-Table` will by default use the width of the console to format columns. – Jeroen Wiert Pluimers Aug 23 '16 at 17:53