-2

How can I format the output file for below wmic command? I need to rework on failed machines

wmic /node:@D:\input.txt /Output:"D:\Result.html" nicconfig where (IPEnabled=TRUE and DHCPEnabled=FALSE) call SetDNSServerSearchOrder ("9.1.1.1","10.1.1.1")

1 Answers1

1

In PowerShell? You collect it in a variable like this:

$output = & wmic '/node:@D:\input.txt' nicconfig where '(IPEnabled=TRUE and DHCPEnabled=FALSE)' call SetDNSServerSearchOrder '("9.1.1.1","10.1.1.1")'

if you're running wmic in the first place. Which you're not.

In PowerShell use the proper cmdlets for WMI operations (e.g. Get-WmiObject):

$dnsServers = '9.1.1.1', '10.1.1.1'
$computers  = Get-Content 'D:\input.txt'

$output = Get-WmiObject -Computer $computers -Class Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=True AND DHCPEnabled=False' |
          ForEach-Object { $_.SetDNSServerSearchOrder($dnsServers) }
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328