簡體   English   中英

通過Powershell獲取名稱和DHCP狀態

[英]Get Name and DHCP status By Powershell

您能幫我嗎,我正在嘗試在txt文件中獲取計算機名稱和此命令的輸出。

為(user_plant.txt)中的/ f%1做>> \\ brspd010 \\ c $ \\ users \\ machael1 \\ desktop \\ nic.txt((wmic / node:%i computersystem得到標題|更多)&(powershell -command“& {Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled = TRUE -ComputerName%i。| Format-Table -Property IPAddress,DHCPEnabled}))

當我在沒有其他運行的情況下運行命令powershell時,效果很好,但是當我嘗試放在一起時卻無法正常工作。

userplant.txt具有:brspd001 brspd002 ...

我需要的是:一個帶有機器名稱和IPV4,DHCP狀態的txt文件,與僅運行powershell命令時顯示的狀態相同。 例:

計算機名稱:BRSPD001 IP 172 ... DHCP啟用true。

或喜歡的人。

你可以幫幫我嗎?

在純PowerShell中,這可能更好。 假設user_plant.txt中每行一台計算機名:

foreach ($Computer in (Get-Content -Path user_plant.txt)) {
    $c = Get-WMIObject -ComputerName $Computer -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = $true"
    "ComputerName: {0}  IP: {1}  DHCPEnabled {2}" -f $Computer,$C.IPAddress[0],$C.DHCPEnabled | Add-Content -Path "\\brspd010\c$\users\machael1\desktop\nic.txt"
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM