I'm trying to add a condition for a command line, which should only be run if the condition is met. I'm doing this by using a WMI Query;

Select * From Win32_NetworkAdapterConfiguration Where DefaultIPGateway=""

So, if the gateway for this deployment has got it should run a command adding a registry setting, if it does not meet the condition it will skip it.

More info:

  • I already have a similar command working that queries WMI for the hostname information. If its hostname begins with XXX%, (the % is a wildcard) it will deploy the command, else it will skip it.
    • If its a certain gateway it should run the command
    • This is already a live Task Sequence, i'm just trying to add this condition to have 1 big sequence

Any help is welcome. Thanks

  • I'm slightly unclear what you're asking: You already have a query, and it works, but you're trying to merge 2 task sequences? Can you elaborate? Are you referring to this? – MDMoore313 Sep 10 '15 at 19:07
  • 1
    BigHomie. Im talking about a query i need to run to check if a PC that is being deployed has a certain gateway. If the gateway is for example than a certain reg key should be imported if it has gateway than another key. I already have this query working in another format, checking the first 3 characters of the hostname. No the link you shared is not what im talking about. thats an if statement. I'm looking for the correct syntax of the wmi query – Saeed Sep 11 '15 at 8:54
  • I gotcha now, edited your question also. Can you post the working host name query as well? – MDMoore313 Sep 11 '15 at 13:07
  • Did my answer help you at all? – MDMoore313 Sep 15 '15 at 15:41

You're looking for a query similar to


If I understand you correctly, you want a task sequence step to run conditionally, this can be accomplished with the task sequence options WMI Query, such that the step will only run if one or all of the conditions are met. Refer to the sample query below.

Sample WMI Query Condition




  • Yo BigHomie, I'm sorry for the late reply. I'm still in the process of testing it out. I'm finishing my new custom image and then I can test it out. But the query seems good, I know about SQL, this seems the way to go. I will update this a.s.a.p. Thanks again – Saeed Sep 17 '15 at 7:21
  • I'm getting an error when testing the query. I'm sorry for the late reply was busy with other projects. Did you test this query? Have you come across this somewhere using this query? I have never seen this being used in a TS and I'm using alot of queries, different onces. The only step I really need to get right is depend on which gateway it gets, thats why this is important to get it working. – Saeed Sep 28 '15 at 8:12

For those who are looking for something like I was looking for. This is the WMI query I'm using. I figured out how to do it. I was doing a query in the DefaultIPGateway but I should have queried the Win32_IP4RouteTable.

Select Mask,Destination,NextHop from Win32_IP4RouteTable WHERE ((Mask='' AND Destination='') AND (NextHop=''))

So is the example gateway.

I used this to check the step in my sequence to check if the defaultgateway is this, if not, it will skip this step.

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.