此代码中的多个输入存在问题:
cls
Install-Module SNMP
Get-Command -Module SNMP
Write-Output ----------------------------------------
$IP = "192.168.15.1"
Write-Output ----------------------------------------
Write-Output "Selected IP is: $IP"
Write-Output ----------------------------------------
Invoke-SnmpWalk -IP $IP -Community public -OID .1.3.6.1.2.1.2.2.1.2 | Format-Table Data -AutoSize -HideTableHeaders | Out-File C:\NameP.ps1xml
Get-Content C:\NameP.ps1xml | Where { $_ -ne "" } | Set-Content C:\NameP1.ps1xml
$Ports = @(Get-Content C:\NameP1.ps1xml | Where-Object { $_.StartsWith("Unit") } )
$NumberOfports = @(Get-Content C:\NameP1.ps1xml | Where-Object { $_.StartsWith("Unit") } ).Count
Write-Output ----------------------------------------
Write-Output "Name ports: "$Ports
Write-Output ----------------------------------------
Write-Output "Number of ports: $NumberOfports"
这是一个交换机的一个IP地址,我需要使用一个带有IP列表或类似脚本的IP地址突然通过一个具有不同IP地址的生产的多个交换机,例如192.168.16.1、192.168.17.1。
我的输出:
CommandType Name Version Source
----------- ---- ------- ------
Function Get-SnmpData 1.0.0.1 SNMP
Function Invoke-SnmpWalk 1.0.0.1 SNMP
Function Set-SnmpData 1.0.0.1 SNMP
----------------------------------------
----------------------------------------
Selected IP is: 192.168.15.1
----------------------------------------
----------------------------------------
Name of ports:
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 1
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 2
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 3
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 4
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 5
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 6
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 7
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 8
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 9
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 10
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 11
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 12
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 13
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 14
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 15
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 16
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 17
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 18
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 19
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 20
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 21
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 22
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 23
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 24
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 25
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 26
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 27
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 28
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 29
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 30
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 31
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 32
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 33
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 34
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 35
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 36
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 37
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 38
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 39
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 40
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 41
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 42
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 43
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 44
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 45 - no sfp inserted
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 46 - no sfp inserted
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 47 - no sfp inserted
Unit: 1 1000BASE-T RJ45 Gigabit Ethernet Frontpanel Port 48 - no sfp inserted
----------------------------------------
Number of ports: 48
我希望此输出获得更多IP。您有可以通过多个IP地址访问的简单解决方案吗? 然后,我仍然使用这些数据。 谢谢你的每一个想法。