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
  • 相关阅读:
    测试平台系列(38) 接入github第三方登录(上)
    测试平台系列(37) 运用装饰器给用例加上执行日志
    测试平台系列(36) 使用全局变量
    测试平台系列(35) 编写全局变量管理页面
    OCP 063中文考试题库(cuug内部资料)第16题
    OCP 063中文考试题库(cuug内部资料)第15题
    D. Strange Housing 题解(思维+染色)
    B. Strange Definition 题解(质因子分解+思维)
    F. Euclid's nightmare 题解(MST+思维)
    D. Fragmentation merging 题解(思维)
  • 原文地址:https://www.cnblogs.com/studio313/p/1622071.html
Copyright © 2011-2022 走看看