Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For example, if I type a command like this:

Get-Childitem | where-object {$_lastwritetime.Day -eq "$data"} |sort-object lastwrittetime

and I want to make an alias for it, I was trying do stuff like this:

set-alias Check -value (and there is above command)

then the alias works, but ignores commands after Get-Childitem.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

For example:

Get-CsAdUser –LdapFilter "Department=IT" | Format-Table DisplayName, Enabled, SipAddress –AutoSize

So how do you create an alias for a command like that? Well, you don't: PowerShell will only let you create aliases for cmdlets, functions, scripts, or files.

So is there a way to work around this problem? Of course there is: there's always a way to work around a problem. (Well, except when there isn't.) For one thing, you could write a script that runs that command for you; there's definitely nothing wrong with that. However, an even better approach might be to create a function that runs your command for you. You know, a function that looks like this one:

Function itusers {Get-CsAdUser –LdapFilter "Department=IT" | Format-Table DisplayName, Enabled, SipAddress –AutoSize}

What we have here is a little function named itusers, a function that returns all the users in the IT department and then displays the value of the DisplayName, Enabled, and SipAddress attributes for each of those users (and in a nicely-formatted table to boot).

Instructions as seen in here.

share|improve this answer
    
Excellent answer. –  Guy Thomas Jan 2 '13 at 13:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.