I deallocate my development Azure VMs every night to conserve my credits. My VMs are all on one vnet using a domain controller. Since it is on the subnet, the domain controllers address never changes.
Every day when I start up my VM I have to configure my network adapter to "Use the following DNS server addresses" for my IPv4 DNS preferred address. I would like to automate this with a script that runs at startup.
I am able to set this property using:
netsh interface ipv4 set dns "Local Area Connection 138" static 10.0.0.4
However, this wont work because the Local Area Connection number increments every startup. I have gotten close to getting the Local Area Connection Name by using:
wmic.exe nic where "NetConnectionStatus=2" get NetConnectionID
But this returns the column header and cannot be used. Value returned looks like this:
NetConnectionID Local Area Connection 138
So my question is how can I set the preferred DNS address of a dynamic Local Area Connection at startup?