Reputation: 1715
I have a few questions about the following code.
Get-DBAAgentJob -SqlInstance *instancename* | Where-Object { $_.HasSchedule -Match "False" }| Out-GridView
I'm curious what are all the things I can filter on in the Where-Object in this line of code. For example, instead of has schedule, if I wanted to look where the job is not enabled, is there a .NotEnabled?
Thanks for the help.
Upvotes: 0
Views: 682
Reputation: 1715
In case someone finds this useful in the future, @Theo's answer was helpful in giving me the base understanding of my question.
I learned more on this today and I will post it to help others in the future.
To answer my question:
This code will tell you all of the properties and methods for a member, in this case the one I was interested in learning more about.
Get-DBAAgentJob -SqlInstance instancename | get-member
This shows me all the properties and methods available, including hasSchedule and isenabled
Upvotes: 0
Reputation: 61148
The Where-Object
clause is a way to filter objects returned from a cmdlet on a certain property.
In your example, it is filtering objects on the HasSchedule
property. The example's filter says this property needs to be False in order for the objects to get piped through the pipeline where the next cmdlet takes them as input.
It tests the objects using the $_
Automatic variable, which represents each object in sequence that is coming in from the Get-DbaAgentJob
cmdlet.
Usually, to find out what an object would look like, you can simply google for it.
In this case, if you look for Get-DBAAgentJob
, you will find this page, where you can look at the function itself.
Here you can find what properties each returned object has:
ComputerName
, InstanceName
, SqlInstance
, Name
, Category
, OwnerLoginName
, IsEnabled
, LastRunDate
, DateCreated
, HasSchedule
, OperatorToEmail
.
As you can see, there is a property IsEnabled
, so you can filter on Not enabled with
Where-Object { -not $_.IsEnabled }
See: PowerShell Logical Operators
If you click the home page for dbatools you'll fine a section called docs where you can learn more.
Browse for free ebooks on PowerShell
Hope that helps
Upvotes: 2