Get-Service | select -First 1
it will list the headers for the service container (first one line only)
Get-Service | Format-Table name, status -AutoSize
This will list all the services showing only 2 headers, name and status in autosized format
Sorting out the output
Get-Service | Format-Table name, status -AutoSize | sort status
This will attempt to sort the output but it will fail because you are sorting after using the Format-Table
You should instead use this:
Get-Service | sort status | Format-Table name, status -AutoSize
Which accomplishes the same but doesn’t give an error message because you are sorting the columns first before formatting the table
Get-Process | Format-Table name, id -GroupBy name -AutoSize | more
This command allows you to see the multiple entries of the same process grouped together
Get-Process | Format-List * -Force | more
This will display all processes in detail (note the ” * ” ) running in the machine; If some fields are displayed in blank, it is because you are not logged on as an administrator; e.g. fields such as Path, Company, CPU, FileVersion, ProductVersion, Description, Product, PriorityClass, etc. may all require administrative rights to be displayed; Some other fields may have no data to be displayed at the moment; e.g. ExitCode should be blank if the process is running fine, so there is no Exit code to be displayed; You can even find threads for the process using this command.
Get-Process | Format-Wide name -Column # (where # is the number of columns you want the wide format to be)
Get-Process | Format-Wide name -AutoSize
NOTE AutoSize will do the maximum number of columns it can without trimming anything
Using the Pipeline to persist information
Get-Process | Format-Table name, id -AutoSize | Out-File c:\PoSh\processtable.txt
This will send the output result to a text file located in the c:\PoSh folder
Tip: at the very end of a Power Shell session, after you have issued several cmdlets, you can save the all the cmdlets typed by using the Out-File parameter to pipe the list into a text file. Example:
h | Out-File c:\PoSh\poshcmdlets.txt
