Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm learning PowerShell with SharePoint and I found this simple powershell example

$timers = (Get-SPTimerJob | ($_.isDisabled -eq $false) )  
$timers

And I get this error

Expressions are only allowed as the first element of a pipeline.

Can you explain the error/How to fix?

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted
$timers = Get-SPTimerJob | where-object { $_.isDisabled -eq $false }
$timers

Just a little bit of syntax error. Get-SPTimerJob needs to be piped to 'something', the where clause (short hand '?'), and use curly braces {} instead of round braces ().

You can use "?" as an alias for where-object, but for production scripts it's recommended to keep the full command names.

share|improve this answer
    
@x0n, why would you not recommend using aliases? –  djeeg Apr 19 '11 at 0:27
    
it's mainly for readability. It's not that big of a sin to use the built-in aliases, but you wouldn't want to use custom aliases for production scripts as this kills portability. Aliases are best used as an aid for interactive use to cut down on typing, or for one-off throwaway scripts. –  x0n Apr 19 '11 at 15:18
add comment

You need to do something like:

$timers = Get-SPTimerJob | where { $_.isDisabled -eq $false }
share|improve this answer
add comment

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.