我的番茄炒蛋
生活如此精彩,挑战无处不在!

导航

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

使用:第一步, 输入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
posted on 2009-12-11 17:02  bluesky  阅读(235)  评论(0编辑  收藏  举报