none
Powershell command... RRS feed

  • Question

  • Hello,

    $ComputerName        = $env:COMPUTERNAME
    Test-NetConnection
    $SourceAddressobject = $env:SourceAddress
    $ComputerName, $SourceAddressobject
    Get-Content C:\temp\servers_Destination.txt | ForEach-Object {Test-NetConnection -computer $_ -port 9997 | select ComputerName, $SourceAddressobject, RemotePort, TcpTestSucceeded} | Export-csv c:\temp\$ComputerName-1.csv
    $ComputerName, $SourceAddressobject
    

    How to get the SourceAddress as an IP not a "MSFT..." raw line? especially in the csv file... the display on screen is the IP but the content in the csv is a raw line MSFT...

    Test-NetConnection
    
    ComputerName           : internetbeacon.msedge.net
    RemoteAddress          : 72.21.81.200
    InterfaceAlias         : Ethernet 2
    SourceAddress          : 10.250.250.6
    PingSucceeded          : True
    PingReplyDetails (RTT) : 13 ms

    Thanks,

    Dom


    Security / System Center Configuration Manager Current Branch / SQL



    • Edited by Felyjos Tuesday, January 21, 2020 8:04 PM
    Tuesday, January 21, 2020 8:02 PM

Answers

  • To get the string value of the address:

    $properties = @(
        'ComputerName',
        @{n='SourceAddress';e={$_.SourceAddress.IpAddress}},
        'TargetAddress',
        'RemotePort',
        'TcpTestSucceeded'
    )
    Get-Content C:\temp\servers_Destination.txt | 
        ForEach-Object {
            Test-NetConnection -computer $_ -port 9997 
        }| 
        select $properties
    
    


    \_(ツ)_/

    • Proposed as answer by jrv Tuesday, January 21, 2020 8:26 PM
    • Marked as answer by Felyjos Tuesday, January 21, 2020 8:35 PM
    Tuesday, January 21, 2020 8:20 PM
  • Trying this one now...

    Excellent, thanks a lot

    $ComputerName        = $env:COMPUTERNAME
    $properties = @(
        'ComputerName',
        @{n='SourceAddress';e={$_.SourceAddress.IpAddress}},
        'RemotePort',
        'TcpTestSucceeded'
    )
    Get-Content C:\temp\servers_Destination.txt | 
        ForEach-Object {
            Test-NetConnection -computer $_ -port 9997 
        }| 
        select $properties | export-csv c:\temp\$ComputerName.csv

    Results:

    #TYPE Selected.TestNetConnectionResult				
    ComputerName	SourceAddress	TargetAddress	RemotePort	TcpTestSucceeded
    10.2.113.70	10.250.250.6		9997	TRUE
    

    Thanks,

    Dom


    Security / System Center Configuration Manager Current Branch / SQL


    • Edited by Felyjos Tuesday, January 21, 2020 8:35 PM
    • Marked as answer by Felyjos Tuesday, January 21, 2020 8:35 PM
    Tuesday, January 21, 2020 8:26 PM

All replies

  • Most of you script makes no sense.

    To get the properties of multiple computers just do this:

    Get-Content C:\temp\servers_Destination.txt | 
        ForEach-Object {
            Test-NetConnection -computer $_ -port 9997 
        }| 
        select ComputerName, SourceAddress, RemoteAddress, RemotePort, TcpTestSucceeded


    \_(ツ)_/


    • Edited by jrv Tuesday, January 21, 2020 8:13 PM
    Tuesday, January 21, 2020 8:13 PM
  • To get the string value of the address:

    $properties = @(
        'ComputerName',
        @{n='SourceAddress';e={$_.SourceAddress.IpAddress}},
        'TargetAddress',
        'RemotePort',
        'TcpTestSucceeded'
    )
    Get-Content C:\temp\servers_Destination.txt | 
        ForEach-Object {
            Test-NetConnection -computer $_ -port 9997 
        }| 
        select $properties
    
    


    \_(ツ)_/

    • Proposed as answer by jrv Tuesday, January 21, 2020 8:26 PM
    • Marked as answer by Felyjos Tuesday, January 21, 2020 8:35 PM
    Tuesday, January 21, 2020 8:20 PM
  • Most of you script makes no sense.

    To get the properties of multiple computers just do this:

    Get-Content C:\temp\servers_Destination.txt | 
        ForEach-Object {
            Test-NetConnection -computer $_ -port 9997 
        }| 
        select ComputerName, SourceAddress, RemoteAddress, RemotePort, TcpTestSucceeded


    \_(ツ)_/


    Hello,

    This one does not work when using an export to file...

    $ComputerName        = $env:COMPUTERNAME
    Get-Content C:\temp\servers_Destination.txt | ForEach-Object {Test-NetConnection -computer $_ -port 9997 | select ComputerName, SourceAddress, RemoteAddress, RemotePort, TcpTestSucceeded} | Export-csv c:\temp\$ComputerName-1.csv

    and in the file there is raw data for the Source address...

    #TYPE Selected.TestNetConnectionResult				
    ComputerName	SourceAddress	RemoteAddress	RemotePort	TcpTestSucceeded
    10.2.113.70	MSFT_NetIPAddress (Name = ";:8??:8??:8@55;?55;55;", CreationClassName = "", SystemCreationClassName = "", SystemName = "")	10.2.113.70	9997	TRUE
    

    Thanks,

    Dom


    Security / System Center Configuration Manager Current Branch / SQL

    Tuesday, January 21, 2020 8:25 PM
  • Trying this one now...

    Excellent, thanks a lot

    $ComputerName        = $env:COMPUTERNAME
    $properties = @(
        'ComputerName',
        @{n='SourceAddress';e={$_.SourceAddress.IpAddress}},
        'RemotePort',
        'TcpTestSucceeded'
    )
    Get-Content C:\temp\servers_Destination.txt | 
        ForEach-Object {
            Test-NetConnection -computer $_ -port 9997 
        }| 
        select $properties | export-csv c:\temp\$ComputerName.csv

    Results:

    #TYPE Selected.TestNetConnectionResult				
    ComputerName	SourceAddress	TargetAddress	RemotePort	TcpTestSucceeded
    10.2.113.70	10.250.250.6		9997	TRUE
    

    Thanks,

    Dom


    Security / System Center Configuration Manager Current Branch / SQL


    • Edited by Felyjos Tuesday, January 21, 2020 8:35 PM
    • Marked as answer by Felyjos Tuesday, January 21, 2020 8:35 PM
    Tuesday, January 21, 2020 8:26 PM