Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell will run wmi query but not in a loop

$
0
0
If I run this command I can get the mac address off a pc with no problems.
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName computer| Select-Object -Property macaddress
 
Now if I put a bunch of workstations into a text file and do a get-content it shows how many objects are in there (51). Yet all three of these scripts are failing for me and I cant figure out why. Replacing the computer name above with the variable and it fails. The error is useless to me, say the RPC server is unavailable. Does anyone see a problem?

foreach ($i in get-content "c:\temp\computers.txt")
{Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $i} | Select-Object -Property macaddress
 
get-content c:\temp\computers.txt | foreach-object {Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $_} | Select-Object -Property macaddress
 
$s = get-content c:\temp\computers.txt
foreach ($i in $s) {Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $i} | Select-Object -Property macaddress

Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>