zoukankan      html  css  js  c++  java
  • PowerShell实战2:Remote_Host

    功能:检测远程主机的硬件信息,安装的软件列表,以及正在运行的进程列表。

    使用:第一步, 输入IP地址或机器名
                  第二步,选择1 (硬件信息),2 (安装的软件列表),3 (运行的进程列表), X (退出)

    源码
    cls
    Write-Host "Please type the name of IP of the host:"
    $IP = Read-Host "Please type the name or IP of the host:"
    Write-Host `nPlease choose: `n1 Hardware Information `n2 Installed Software `n3 Running Processes `nX EXIT
    do {
    $Choice = Read-Host "Please choose a number: 1.Hardware 2.Software 3.Processes X.EXIT"
    switch ($Choice)
        {
            X {EXIT}
            1 {
            $Model = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $IP).Model; `
            $ST = (Get-WmiObject -Class Win32_BIOS -ComputerName $IP).SerialNumber; `
            $CPU = (Get-WmiObject -Class Win32_Processor -ComputerName $IP)| foreach {$_.Name}; `
            $RAM = (Get-WmiObject -Class Win32_ComputerSystem -ComputerName $IP).TotalPhysicalMemory/1GB; `
            $HDD = Get-WmiObject -Class Win32_DiskDrive -ComputerName $IP | foreach {$_.Size/1GB}; `
            $CDROM = Get-WmiObject -Class Win32_CDROMDrive -ComputerName $IP | foreach {$_.Caption} ; `
            $NIC = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $IP | where-Object {$_.IPAddress -like "*.*" } | foreach {$_.Description}; `
            Write-Host `nModel:$Model, `nServiceTag:$ST, `nCPU:$CPU, `nRAM:$RAM GB, `nHDD:$HDD GB, `nCD-ROM:$CDROM `n$NIC
            }
            2 {
            #Windows 2003 does not support Win32_Product by default.
            $APP = Get-WmiObject -Class Win32_Product -ComputerName $IP| Sort-Object Name | Format-List ; `
            $APP
            }
            3 {
            $PROCESS = Get-WmiObject -Class Win32_Process -ComputerName $IP | Sort-Object caption | Select-Object Caption, ProcessID, Path | Format-List; `
            $PROCESS
            } 
            default {Write-host "Wrong Choice!" -ForegroundColor Red }
        }
        }
    while ($Choice -ne "X")
    结果:
    Please type the name of IP of the host:
    Please choose:
    1 Hardware Information
    2 Installed Software
    3 Running Processes
    X EXIT
    Model:OptiPlex 170L                
    ServiceTag:17K1XM9
    CPU: Intel(R) Pentium(R) 4 CPU 2.80GHz
    RAM:0.498031616210938 GB
    HDD:74.5049428939819 GB
    CD-ROM:SAMSUNG CD-ROM SC-148A
    Intel(R) PRO/100 VE Network Connection - Packet Scheduler Miniport
  • 相关阅读:
    分布式机器学习:算法、理论与实践——【1】
    LLVM Cookbook
    【前端】Webpack 进阶
    Noip2015 运输计划 树上差分 二分答案
    bzoj 2259: [Oibh]新型计算机 最短路 建模
    888E
    [ZJOI2012]旅游 对偶图 树的直径
    [HAOI2007]理想的正方形 单调队列 暴力
    bzoj1457: 棋盘游戏 SG函数 Nim
    Bomb HDU
  • 原文地址:https://www.cnblogs.com/studio313/p/1622071.html
Copyright © 2011-2022 走看看