How do I get the computername for results of script

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 9 months ago.

  • Author
    Posts
  • #6452

    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
    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"}},ServiceName,Description

    by coderaven at 2013-02-28 12:47:33

    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

    Get-WMIObject -ComputerName (get-content c:\temp\ncc.csv) -Query "Select * from Win32_NetworkAdapterConfiguration where IPEnabled = True" | Select DNSHostname,@{Name='IPAddresses';Expression={$_.IPAddress -join "`n"}},ServiceName,Description

    Is that what you are looking for?

You must be logged in to reply to this topic.