国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PowerShell > 正文

PowerShell腳本實現(xiàn)檢測網(wǎng)絡(luò)內(nèi)主機類型

2020-05-30 20:18:35
字體:
供稿:網(wǎng)友

最近一直在寫一個自動檢測網(wǎng)絡(luò)內(nèi)主機類型的腳本。基本功能可以實現(xiàn)判斷主機操作系統(tǒng)類型,如果是域內(nèi)的主機可以獲取主機的硬件參數(shù)和性能參數(shù),并判斷是否存在網(wǎng)絡(luò)設(shè)備。對一個運維人員來說往往需要盡快熟悉一個陌生的網(wǎng)絡(luò)。所以這個腳本就很方便了,如果有更好的建議歡迎指正感謝!
代碼如下:
############################################
#Author:Lixiaosong
#Email:lixiaosong8706@gmail.com
#For:檢測/24掩碼網(wǎng)絡(luò)內(nèi)主機系統(tǒng)類型并獲取windows主機參數(shù)
#Version:1.0
##############################################
Param(
[Parameter(Mandatory=$true)]$Network
)
$Ip=for($i= 1; $i-ile255; $i+= 1){"$Network.$i"}
foreach($Ipaddressin$IP){
#檢測相關(guān)端口狀態(tài)
$Port3389=3389 | %{ echo ((new-objectNet.Sockets.TcpClient).Connect("$Ipaddress",$_)) "$true"} 2>$null
$Port22=22 | %{ echo ((new-objectNet.Sockets.TcpClient).Connect("$Ipaddress",$_)) "$true"} 2>$null
$Port23=23 | %{ echo ((new-objectNet.Sockets.TcpClient).Connect("$Ipaddress",$_)) "$true"} 2>$null
$Pingtest=Test-connection-ComputerName$IPaddress-quiet
if($Port3389-like"$true"){
#服務(wù)器信息
$HostSN=(GWMI-ComputerName"$Ipaddress"win32_bios).SerialNUmber
$HostFirm=(GWMI-ComputerName"$Ipaddress"win32_bios).Manufacturer
$HostModel=(GWMI-ComputerName"$Ipaddress"Win32_ComputerSystem).Model
#主機信息
$HostName=(GWMI-ComputerName"$Ipaddress"Win32_ComputerSystem).DNSHostName
$DomainName=(GWMI-ComputerName"$Ipaddress"Win32_ComputerSystem).Domain
#服務(wù)器硬件資源信息
$Freemem=(GWMI-ComputerName"$Ipaddress"win32_OperatingSystem).FreePhysicalMemory#空余物理內(nèi)存
$Totalmem=(GWMI-ComputerName"$Ipaddress"win32_OperatingSystem).TotalVisibleMemorySize#總物理內(nèi)存
$cpu=((get-counter-ComputerName"$IPaddress"-counter"/processor(_total)/% processor time").CounterSamples|where{$_.InstanceName -eq"_total"}).CookedValue
$DiskRead=" {0:0.0} KB"-f($(((get-counter-ComputerName"$Ipaddress"-counter"/LogicalDisk(_total)/Disk Read Bytes/sec").CounterSamples|where{$_.InstanceName -eq"_total"}).CookedValue) / 1KB)
$DiskWrite="{0:0.0} KB"-f($(((get-counter-ComputerName"$Ipaddress"-counter"/LogicalDisk(_total)/Disk Write Bytes/sec").CounterSamples|where{$_.InstanceName -eq"_total"}).CookedValue) /1KB)
$NetworkSent=" {0:0.0} KB"-f($((Get-Counter-ComputerName"$Ipaddress"-Counter"/Network Interface(*)/Bytes Sent/sec").CounterSamples|%{$_.CookedValue}|sort|select-last1) / 1KB)
$NetworkReceive=" {0:0.0} KB"-f($((Get-Counter-ComputerName"$IPaddress"-Counter"/Network Interface(*)/Bytes Received/sec").CounterSamples|%{$_.CookedValue}|sort|select-last1) / 1KB)
$Havecpu= "{0:0.0} %"-f$cpu
$Permem="{0:0.0} %"-f((($Totalmem-$Freemem)/$Totalmem)*100)
$Disks= GWMI-ComputerName"$IPaddress"win32_logicaldisk|?{$_.drivetype -eq3}
#獲取域內(nèi)Windows主機參數(shù)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 海安县| 田东县| 彰化市| 鄂尔多斯市| 蒲江县| 扎兰屯市| 巴彦县| 临夏县| 临洮县| 济源市| 吴川市| 延川县| 新昌县| 云霄县| 当涂县| 镇原县| 淳化县| 兴海县| 平昌县| 新干县| 郴州市| 尚志市| 延边| 武穴市| 新昌县| 合肥市| 呼和浩特市| 黄山市| 信丰县| 大荔县| 尚义县| 嫩江县| 常宁市| 隆化县| 陇川县| 山东省| 会宁县| 黄龙县| 温泉县| 五河县| 蛟河市|