0
votes

could you help me with, i'm trying to get the computer name and the output from this command below in a txt file.

for /f %1 in (user_plant.txt) do >>\brspd010\c$\users\machael1\desktop\nic.txt ((wmic /node:%i computersystem get caption | more) & (powershell -command "& {Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName %i. | Format-Table -Property IPAddress, DHCPEnabled}))

the command powershell when i run without the rest, it's works fine, but when i try to put together not work.

userplant.txt has: brspd001 brspd002 ...

My needly is: A txt file with Name of machine and IPV4,DHCP status as the same showed when i run only the powershell command. example:

Computername: BRSPD001 IP 172 ... DHCP Enabled true.

or someone like it.

could you help me?

1
You are using %i in your command, but %1 as the index to your for loop - is this a typo, and your intent to use %i? Also, does user_plant.txt contain the list of computers you want this for? Please edit your question to include some sample input and output. - Jeff Zeitlin
Done Jeff as you request. - Elivelton Andrade

1 Answers

0
votes

This is probably better done in pure PowerShell. Assuming one computername per line in user_plant.txt:

foreach ($Computer in (Get-Content -Path user_plant.txt)) {
    $c = Get-WMIObject -ComputerName $Computer -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = $true"
    "ComputerName: {0}  IP: {1}  DHCPEnabled {2}" -f $Computer,$C.IPAddress[0],$C.DHCPEnabled | Add-Content -Path "\\brspd010\c$\users\machael1\desktop\nic.txt"
}