Hi All,
I am very new to PowerShell and I just start to play with it last week and base on my requirement now. I got this native windows command "nbtstat" that I run to validate remote computer hostname. I am trying to make a function to pass ip-address to the command. Right now I am trying to make the code run first. The command output will be like below:
PS C:\> nbtstat -A 10.xx.xx.xxx
Local Area Connection:
Node IpAddress: [0.0.0.0] Scope Id: []
Host not found.
Wireless Network Connection:
Node IpAddress: [10.xx.xx.xxx] Scope Id: []
NetBIOS Remote Machine Name Table
Name Type Status
---------------------------------------------
COMPUTERNAME01 <00> UNIQUE Registered
LAB01 <00> GROUP Registered
LAB01 <1E> GROUP Registered
COMPUTERNAME01 <20> UNIQUE Registered
MAC Address = XX-XX-XX-XX-XX-XX
I want the function to return "COMPUTERNAME01" or the hostname only for every ip-address that I check.
Here is what I got so far and I do not know how to split the result to display the "COMPUTERNAME01" only. I am open for any suggestion from the experts. Many thanks in advance.
$nbtstat_out = nbtstat -A 10.xx.xx.xxx | Select-String -Pattern "\s*(\S+)\s+<20>"; $nbtstat_out
PowerShell Console:
COMPUTERNAME01 <20> UNIQUE Registered