How to force PowerShell to display all the properties by default


Welcome to the second post of my series on 'How to get more results from PowerShell'.

- How to force PowerShell to display all the properties by default

This tutorial will show you how to force PowerShell to display all the properties by default. By default, many cmdlets will only display a select few properties. Using this switch will force it to display all properties.

================================================================

All tutorials in this series -
- How to create PowerShell outputs to show all data without truncation - Link
- How to force PowerShell to display all the properties by default - Link
- How to force PowerShell to export multi-value properties when exporting to csv files - Link

Related PowerShell Tutorials
- How to create basic PowerShell scripts - Link
- How to create basic PowerShell scripts with Export-CSV - Link
- How to create basic PowerShell scripts with Import-CSV - Link

================================================================

When you start creating PowerShell reports, you will quickly see that there are many different ways to output your results or queries. Most day to day administration will involve simple queries to get the basic details of an AD user for example. This simple query will involve using the cmdlet 'get-aduser' with the identity of the Active Directory User object, and output the results to either the screen or a file type (usually txt or csv file).

Simple scripts to output the main properties of an AD user.

Output to screen
get-aduser user01 | fl

Output to txt file
get-aduser user01 | fl >c:\reports\user01details.txt

Output to csv file
get-aduser user01 | export-csv -NoTypeInformation c:\reports\User01.csv

This brings me to the issue, PowerShell not displaying all the properties by default.
By default, using the simple cmdlet 'get-aduser' will output the most common object properties - ten results. But adding a simple parameter will display all 151 properties!

===============================================================

PowerShell not showing all properties of an object

As you can see below, the basic cmdlet 'get-aduser' only outputs 10 main properties.
get-aduser user01 | fl    - Shows 10 properties














But adding the switch -Properties with the * value, the script will now output all 150 properties.

get-aduser user01 -Properties * | fl    - Shows 151 properties

















All three output scripts can be updated to include all properties and provide all properties.

Output to screen - (See image above)
get-aduser user01 -Properties * | fl

Output to txt file
get-aduser user01 -Properties * | fl >c:\reports\user01details.txt


















Output to csv file
get-aduser user01 -Properties * | export-csv -NoTypeInformation c:\reports\User01details.csv

Note that exporting to CSV may introduce more issues when trying to output properties with mulitple values (as above). I will show you how to resolve this in the next article in this series.

-------------------------------------------------------------------------------------------

Congratulations !!!
You now know how to create PowerShell scripts that display all properties by default.

-------------------------------------------------------------------------------------------

Check out a list of ALL of my tutorials here - Link




No comments:

Post a Comment