There are many times when I need to do something like this:
get-Whatever | select –first 1 | format-list –property *
Normally its because I need to discover the properties on an object and see some representative data at the same time. If I just wanted the properties I could use Get-Member.
Getting tired of typing
select –first 1 | format-list –property *
Its a bit repetitive & boring I decided to look at a function to do this for me and ended up with this
function Select1FullList {
param (
[scriptblock]$scriptblock
)
Invoke-Command -ScriptBlock $scriptblock |
Select-Object -First 1 |
Format-List -Property *
}
New-Alias -Name sfl -Value Select1FullList
I decided on a scriptblock as input because I wasn’t sure what I’d be wanting to see. For instance
Get-mailbox | Get-mailboxstatistics
could be be my input.
I also decided to use an alias as this is a command line tool for use while I’m writing code. My feelings on aliases in scripts still stand.
Still deciding if I need to add a computername parameter to give it remoting capabilities.
Any ways its going into my profile for now & we’ll see how it works out.