简体   繁体   中英

powershell net view not showing all computer names on network

Using the one-liner

switch -regex (NET.EXE VIEW) { "^\\\\(?<Name>\S+)\s+" { $matches.Name } }

To get a list of all computers on the network, but for some reason, this only returns a partial list, could it be a work-group related issue?

I can see all the computers on the network under the windows network tab and log in successfully, though.

Made a bit of a script for this that grabs all of the network computers via arp -a, hostnames etc, with a progress bar, and then feeds them to an array that I can use.

Add-Type -assembly System.Windows.Forms

## -- Create The Progress-Bar
$ObjForm = New-Object System.Windows.Forms.Form
$ObjForm.Text = "Initial Setup"
$ObjForm.Height = 100
$ObjForm.Width = 500
$ObjForm.BackColor = "#000000"
$ObjForm.FormBorderStyle = 'None'
$ObjForm.ControlBox = $False

$ObjForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$ObjForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$ObjForm.TopMost = $True

## -- Create The Label
$ObjLabel = New-Object System.Windows.Forms.Label
$ObjLabel.Text = "Starting. Please wait ... "
$ObjLabel.Left = 5
$ObjLabel.Top = 10
$ObjLabel.Width = 500 - 20
$ObjLabel.Height = 15
$ObjLabel.Font = "Tahoma"
$ObjLabel.ForeColor = "#FFFFFF"
## -- Add the label to the Form
$ObjForm.Controls.Add($ObjLabel)

$PB = New-Object System.Windows.Forms.ProgressBar
$PB.Name = "PowerShellProgressBar"
$PB.Value = 0
$PB.Style = "Continuous"
$PB.ForeColor = "#FFC20E"
$PB.BackColor = "#111111"

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 500 - 40
$System_Drawing_Size.Height = 20
$PB.Size = $System_Drawing_Size
$PB.Left = 5
$PB.Top = 40
$ObjForm.Controls.Add($PB)

## -- Show the Progress-Bar and Start The PowerShell Script
$ObjForm.Show() | Out-Null
$ObjForm.Focus() | Out-NUll
$ObjLabel.Text = "Starting. Please wait ... "
$ObjForm.Refresh()

Start-Sleep -Seconds 1

## -- Execute The PowerShell Code and Update the Status of the Progress-Bar

$Activity = "Processing items"
$NameArray = arp -a
$ArpArray = @()
$FinalArray = @()

foreach ($object in $NameArray)
{
    $ArpArray += ($object -split "\s+")[1] -replace "Internet", ""
}

$TotItems = $ArpArray.Count
$Count = 0

$ParseArray = $ArpArray | Where { $_ -ne '' }
foreach ($address in $ParseArray)
{
    #write-host $address
    $Stringer = $address
    try { $Name = [System.Net.Dns]::GetHostByAddress($Stringer).Hostname }
    catch [Exception]{ $Name = "" }
    $FinalArray += $Name

    $Count++
    $percentComplete = ($Count/$TotItems * 100)
    $PB.Value = $percentComplete
    $ObjLabel.Text = "Getting Network Computer Names"
    $ObjForm.Refresh()
    Start-Sleep -Milliseconds 150

}

$FinalArray = $FinalArray | Where { $_ -ne "" }
$FinalArray = $FinalArray | Select -Unique
#$FinalArray

$ObjForm.Close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM