远程搜集主机网卡信息
|Word Count:533|Reading Time:2mins|Post Views:
远程搜集主机网卡信息
开启功能
客户端
默认情况下,在Windows 10或者11 首次执行powershell脚本会提示”系统禁止脚本运行“的错误。这是因为M$为了安全,把powershell的脚本执行策略设定为有数字证书的才允许执行。因此,需要执行脚本的方法一个是使用合法的数字证书对脚本进行签名:
1 2 3 4 5 6 7 8
|
$cert = Get-PfxCertificate -FilePath "test.pfx"
Set-AuthenticodeSignature -FilePath "demo.ps1" ` -Certificate $cert -IncludeChain "All" ` -TimeStampServer "http://timestamp.verisign.com/scripts/timstamp.dll"
|
或者我们干脆取消这一限制:
1 2
| set-executionpolicy remotesigned
|
服务端
如果服务器已经加入Windows域环境的话,
1 2 3 4 5
| Enable-PSRemoting -Force Set-Item -Path WSMan:\localhost\client\trustedhosts -Value * -Force
|
执行搜集
1 2 3 4 5 6 7 8 9 10 11
| $ServerList=( 'servera.example.com','serverb.example.com','serverc.example.com')
foreach ( $ServerName in $ServerList ) { Invoke-Command -ComputerName $ServerName -Command {Get-Content Env:COMPUTERNAME} Invoke-Command -ComputerName $ServerName -Command {Get-Netadapter |ft} Invoke-Command -ComputerName phpv153003.firstshare.cn -Command { Get-NetIPAddress | Sort -Property ifIndex |ft -autosize |ft } }
|
输出结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| servera
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed ---- -------------------- ------- ------ ---------- --------- NIC4 Broadcom NetXtreme Gigabit Ethernet NIC3 Broadcom NetXtreme Gigabit Ethernet NIC2 Broadcom NetXtreme Gigabit Ethernet 2 Up 54-9F-35-15-FD-5D 1 Gbps NIC1 Broadcom NetXtreme Gigabit Ethernet
ifIndex IPAddress PrefixLength PrefixOrigin SuffixOrigin AddressState PolicyStore ------- --------- ------------ ------------ ------------ ------------ ----------- 1 ::1 128 WellKnown WellKnown Preferred ActiveStore 1 127.0.0.1 8 WellKnown WellKnown Preferred ActiveStore 3 fe80::5efe:10.12.153.103%3 128 WellKnown Link Deprecated ActiveStore 7 fe80::5efe:172.31.153.3%7 128 WellKnown Link Deprecated ActiveStore 8 169.254.31.27 16 WellKnown Link Tentative ActiveStore 8 fe80::7c00:7d4d:22ea:1f1b%8 64 WellKnown Link Deprecated ActiveStore
|