WMI query to check for IP default gateway for OSD

8,926

Solution 1

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='0.0.0.0' AND Destination='0.0.0.0') AND (NextHop='10.0.0.1'))

So 10.0.0.1 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.

Solution 2

You're looking for a query similar to

SELECT * FROM WIN32_NETWORKADAPTERCONFIGURATION WHERE DEFAULTIPGATEWAY LIKE "192.168.1.1"

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

References:

https://msdn.microsoft.com/en-us/library/Aa394217(v=VS.85).aspx

https://technet.microsoft.com/en-us/library/bb632701.aspx

Share:
8,926

Related videos on Youtube

Saeed
Author by

Saeed

Updated on September 18, 2022

Comments

  • Saeed
    Saeed over 1 year

    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="192.168.1.1"
    

    So, if the gateway for this deployment has got 192.168.1.1 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

    • MDMoore313
      MDMoore313 over 8 years
      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?
    • Saeed
      Saeed over 8 years
      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 192.168.1.1 than a certain reg key should be imported if it has 192.168.2.1 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
    • MDMoore313
      MDMoore313 over 8 years
      I gotcha now, edited your question also. Can you post the working host name query as well?
    • MDMoore313
      MDMoore313 over 8 years
      Did my answer help you at all?
  • Saeed
    Saeed over 8 years
    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
    Saeed over 8 years
    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.