xuxiaohui9216 发表于 2018-9-3 10:35:44

PowerShell实战2:Remote_Host

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")

页: [1]
查看完整版本: PowerShell实战2:Remote_Host