Name NetworkInterfaceType Description ----------------------------------- vEthernet (Default Switch) Ethernet Hyper-V Virtual Ethernet Adapter Ethernet 2 Ethernet USB Ethernet Local Area Connection* 1 Wireless80211 Microsoft Wi-Fi Direct Virtual Adapter Local Area Connection* 2 Wireless80211 Microsoft Wi-Fi Direct Virtual Adapter #2 WLAN Wireless80211 Killer(R) Wi-Fi6 AX1650s 160MHz Wireless Network Adapter (201D2W) Bluetooth Network Connection Ethernet Bluetooth Device (Personal Area Network) Loopback Pseudo-Interface1 Loopback Software Loopback Interface 1
但是,您找到的.NET方法可能不直接包含所需信息。在我们的示例中,GetAllNetworkInterfaces() 返回所有网络适配器,但要获取它们的 MAC 地址,则需要深入了解 .NET 对象树。这就使得使用这种技术变得更加困难(但也令人兴奋和有益)。
Name Status Mac SpeedGb -------------------- vEthernet (Default Switch) Up 00-15-5D-58-46-A810 Ethernet 2 Up 80-3F-5D-05-58-911 Local Area Connection* 1 Down 24-EE-9A-54-1B-E6 Local Area Connection* 2 Down 26-EE-9A-54-1B-E5 WLAN Down 24-EE-9A-54-1B-E50,78 Bluetooth Network Connection Down 24-EE-9A-54-1B-E90,003
1..255 | ForEach-Object { # create the IP address to ping # make sure you adjust this to your segment! $ip = "192.168.2.$_" # execute ping.exe and disregard the text output ping -n1-w500$ip > $null # instead return the translated return value found in $LASTEXITCODE [PSCustomObject]@{ IpAddress = $ip Status = $translation[$LASTEXITCODE] } }
Now, when it is time to use the secrets, you need a way to convert secure strings back to plain text. This is what this script does: 现在,当需要使用这些机密信息时,您需要一种将安全字符串转换回纯文本的方法。此脚本的操作:
1 2 3 4 5 6 7
$hash = Import-Clixml-Path$Path # important: MUST cast $keys to [string[]] or else you cannot modify the hash # in the loop: [string[]]$keys = $hash.Keys $keys | ForEach-Object { $hash[$_] = [PSCredential]::new('xyz', $hash[$_]).GetNetworkCredential().Password }