首先,請停止使用PowerShell像往常一樣的腳本語言。
PowerShell使用對象和解析字符串是絕對不是做你想做的事情的好方法。我必須修改你的腳本到我的語言來得到$ data的東西
對於我來說這裏的東西沒有任何意義,但是你構造了一個數組的哈希表,並且我給你開發它的方法。
所以使用$數據,你可以寫:
foreach ($key in $data.keys)
{
write-Host ("The name is {0}, the value is {1}" -f $key, $data[$key])
}
對我來說,它提供了:
The name is [02]: fe80::391a:2817:8f3e:6f2f, the value is System.Object[]
The name is [02]: Intel(R) WiFi Link 5300 AGN, the value is System.Object[]
The name is [02]: fe80::c70:cc38:cf64:eb27, the value is System.Object[]
The name is [01]: 192.168.183.1, the value is System.Object[]
The name is [01]: 192.168.0.3, the value is System.Object[]
The name is [03]: VMware Virtual Ethernet Adapter for VMnet1, the value is System.Object[]
The name is [05]: Microsoft Virtual WiFi Miniport Adapter, the value is System.Object[]
The name is [02]: fe80::5d48:c4a:5987:ee73, the value is System.Object[]
The name is [04]: VMware Virtual Ethernet Adapter for VMnet8, the value is System.Object[]
The name is [01]: 192.168.234.1, the value is System.Object[]
The name is [01]: Intel(R) 82567LM Gigabit Network Connection, the value is System.Object[]
因爲$數據[$關鍵]是一個數組。你可以這樣寫:
foreach ($key in $data.keys)
{
write-Host ("The name is {0}" -f $key)
foreach($line in $data[$key])
{
Write-Host ("`t$line")
}
}
對我來說,它提供了:
The name is [02]: fe80::391a:2817:8f3e:6f2f
The name is [02]: Intel(R) WiFi Link 5300 AGN
Nom de la connexion : Connexion réseau sans fil
État : Support déconnecté
The name is [02]: fe80::c70:cc38:cf64:eb27
The name is [01]: 192.168.183.1
The name is [01]: 192.168.0.3
The name is [03]: VMware Virtual Ethernet Adapter for VMnet1
Nom de la connexion : VMware Network Adapter VMnet1
DHCP activé : Non
Adresse(s) IP
The name is [05]: Microsoft Virtual WiFi Miniport Adapter
Nom de la connexion : Connexion réseau sans fil 2
État : Support déconnecté
The name is [02]: fe80::5d48:c4a:5987:ee73
The name is [04]: VMware Virtual Ethernet Adapter for VMnet8
Nom de la connexion : VMware Network Adapter VMnet8
DHCP activé : Non
Adresse(s) IP
The name is [01]: 192.168.234.1
The name is [01]: Intel(R) 82567LM Gigabit Network Connection
Nom de la connexion : Connexion au réseau local
DHCP activé : Oui
Serveur DHCP : 192.168.0.254
Adresse(s) IP
謝謝=)我瞭解WMI。我甚至明確表示,我知道在我的問題中有更好的方法來獲取信息,因爲我知道人們會建議WMI =)。這不是我現在感興趣的東西。我只是用這個輸出的systeminfo作爲可能需要解析的文本的一個例子。 – 2011-05-19 09:11:08
由於沒有答案我回答我的問題,(這是因爲問題的性質,真的),我想「關閉」這個問題,我選擇一個,我認爲這三個問題中最有用。 – 2011-05-22 21:45:02