2

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?

4
$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.

2
  • @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
0

You need to do something like:

$timers = Get-SPTimerJob | where { $_.isDisabled -eq $false }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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