How do I get the computername for results of script

by Christopher.Ellis at 2013-02-28 06:09:07

I run this command, I get DHCPEnabled IP address, Default Gateway, but no computer name. what parameter must i add to get computername? script below

PS C:> get-wmiobject -computername (get-content c:\temp\ncc.csv) win32_networkadapterconfiguration | where-object {$.Ipaddress}

DHCPEnabled : False
IPAddress : {10.35.1.51}
DefaultIPGateway : {10.35.1.1}
DNSDomain :
ServiceName : VMXNET
Description : VMware PCI Ethernet Adapter #2
Index : 9

DHCPEnabled : False
IPAddress : {10.35.1.27}
DefaultIPGateway : {10.35.1.1}
DNSDomain :
ServiceName : vmxnet3ndis6
Description : vmxnet3 Ethernet Adapter #2
Index : 8

DHCPEnabled : False
IPAddress : {10.35.1.26}
DefaultIPGateway : {10.35.1.1}
DNSDomain :
ServiceName : VMXNET
Description : VMware PCI Ethernet Adapter
Index : 9
by ArtB0514 at 2013-02-28 07:18:44
Get-WMIObject doesn’t display all its properties by default. Use this to find the candidate properties for you to specifiy:
get-wmiobject -computername (get-content c:\temp\ncc.csv | Select-Object -First 1) win32_networkadapterconfiguration |
where-object {$
.Ipaddress} | Select-Object -First 1 | Get-Member -MemberType *property | Where-Object {$.Name -match "name"}

This returns two potentials that might solve your problem: PSComputerName and DNSHostName. Remove the Where-Object clause to see all the available properties.
by Christopher.Ellis at 2013-02-28 07:56:33
what does Select-Object -First 1 do? I want to use DNSHostname How would i apply that to the script above?
by AlexBrassington at 2013-02-28 09:07:10
Select-Object -First 1 gets the first object from an array:


PS C:\Windows\system32> get-help select-object -Parameter First

-First <int>
Specifies the number of objects to select from the beginning of an array of input objects.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false


Essentially it is being used to grab one copy of the items returned so you can see what properties it has.
by ArtB0514 at 2013-02-28 10:00:04
I’d break the task into two parts, first collecting the data unmodified, and then doing something with it. Here’s an example:
$Data = get-wmiobject -computername (get-content c:\temp\ncc.csv) win32_networkadapterconfiguration | where-object {$
.Ipaddress}
$Data | Select DNSHostname,@{Name='IPAddresses';Expression={$_.IPAddress -join "n&quot;}},ServiceName,Description</code></blockquote>by coderaven at 2013-02-28 12:47:33<blockquote>First, you just want the adapters that have IPEnabled and you only want to send those over the network. To speed things up, use the -ThrottleLimit switch<br><br><code>Get-WMIObject -ComputerName &#40;get-content c:\temp\ncc.csv&#41; -Query &quot;Select * from Win32_NetworkAdapterConfiguration where IPEnabled = True&quot; | Select DNSHostname,@{Name=&#39;IPAddresses&#39;;Expression={$_.IPAddress -join &quot;n"}},ServiceName,Description


Is that what you are looking for?