PowerShell for Windows Admins

Sep 23 2013   12:26PM GMT

Select and List

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: