From bc33af77c4ac702e6468d38817ad5126ae1d9534 Mon Sep 17 00:00:00 2001 From: deadlydog Date: Tue, 31 Oct 2023 09:06:23 -0600 Subject: [PATCH] tip: New tip for select-object * --- ...t-object--to-see-all-object-properties.ps1 | 34 +++++++++++++++++++ src/tiPS/PowerShellTips.json | 10 ++++++ 2 files changed, 44 insertions(+) create mode 100644 src/PowerShellTips/2023-10-31-use-select-object--to-see-all-object-properties.ps1 diff --git a/src/PowerShellTips/2023-10-31-use-select-object--to-see-all-object-properties.ps1 b/src/PowerShellTips/2023-10-31-use-select-object--to-see-all-object-properties.ps1 new file mode 100644 index 0000000..294fc3f --- /dev/null +++ b/src/PowerShellTips/2023-10-31-use-select-object--to-see-all-object-properties.ps1 @@ -0,0 +1,34 @@ +$tip = [tiPS.PowerShellTip]::new() +$tip.CreatedDate = [DateTime]::Parse('2023-10-31') +$tip.Title = 'Use Select-Object * to see all object properties' +$tip.TipText = @' +When an object is written to the console, PowerShell by default hides many of its properties. This is to make the output easier to read, but it can hide many useful properties that you may not know exist. This can be detrimental when interactively exploring objects in the console. + +To see all properties of an object, and their values, use the `Select-Object` cmdlet with the `-Property *` parameter. +'@ +$tip.Example = @' +# See the properties of an object shown by default (for comparison). +Get-Process | Select-Object -First 1 + +# See all properties of an object. +Get-Process | Select-Object -First 1 -Property * + +# Shorthand alternatives for Select-Object -Property *. +Get-Process | Select-Object -First 1 * +Get-Process | Select-Object * +Get-Process | Select * +'@ +$tip.Urls = @( + 'https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object' +) +$tip.Category = [tiPS.TipCategory]::NativeCmdlet # Community, Editor, Module, NativeCmdlet, Performance, Security, Syntax, Terminal, or Other. + +# Community: Social events and community resources. e.g. PowerShell Summit, podcasts, etc. +# Editor: Editor tips and extensions. e.g. VSCode, ISE, etc. +# Module: Modules and module tips. e.g. PSScriptAnalyzer, Pester, etc. +# NativeCmdlet: Native cmdlet tips. e.g. Get-Process, Get-ChildItem, Get-Content, etc. +# Performance: Tips to improve runtime performance. e.g. foreach vs ForEach-Object, ForEach-Object -Parallel, etc. +# Security: Security tips. e.g. ExecutionPolicy, Constrained Language Mode, passwords, etc. +# Syntax: Syntax tips. e.g. splatting, pipeline, etc. +# Terminal: Terminal shortcuts and tips. e.g. PSReadLine, Windows Terminal, ConEmu, etc. +# Other: Tips that don't fit into any of the other categories. diff --git a/src/tiPS/PowerShellTips.json b/src/tiPS/PowerShellTips.json index eeb8a1f..9c6e5ea 100644 --- a/src/tiPS/PowerShellTips.json +++ b/src/tiPS/PowerShellTips.json @@ -399,5 +399,15 @@ "https://devblogs.microsoft.com/scripting/how-to-use-powershell-to-write-to-event-logs/" ], "Category": 3 + }, + { + "CreatedDate": "2023-10-31T00:00:00", + "Title": "Use Select-Object * to see all object properties", + "TipText": "When an object is written to the console, PowerShell by default hides many of its properties. This is to make the output easier to read, but it can hide many useful properties that you may not know exist. This can be detrimental when interactively exploring objects in the console.\r\n\r\nTo see all properties of an object, and their values, use the `Select-Object` cmdlet with the `-Property *` parameter.", + "Example": "# See the properties of an object shown by default (for comparison).\r\nGet-Process | Select-Object -First 1\r\n\r\n# See all properties of an object.\r\nGet-Process | Select-Object -First 1 -Property *\r\n\r\n# Shorthand alternatives for Select-Object -Property *.\r\nGet-Process | Select-Object -First 1 *\r\nGet-Process | Select-Object *\r\nGet-Process | Select *", + "Urls": [ + "https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object" + ], + "Category": 3 } ]