powershell 获取已加载的常规设备信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 获取已加载的常规设备信息相关的知识,希望对你有一定的参考价值。
<#
.Synopsis
Get-GeneralInfo gathers general info about the device to provide in the output
.DESCRIPTION
Get-GeneralInfo gathers general info about the device including hostname, model to display in the final output
#>
function Get-GeneralInfo {
#--------------------------------------------------------------------------------------
#Getting the host name with error control
try{
$Script:hostname = Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name
}
catch
{
$Script:hostname = "ERROR - Could not determine"
$Script:QC = $false
}
#--------------------------------------------------------------------------------------
#Getting the manufacturer with error control
try{
$manufacturer = Get-CimInstance CIM_ComputerSystem
$Script:manufacturer = $manufacturer.Manufacturer
}
catch
{
$Script:manufacturer = "ERROR - Could not determine"
$Script:QC = $false
}
#--------------------------------------------------------------------------------------
#Getting the model with error control
try{
$model = Get-CimInstance CIM_ComputerSystem
$Script:model = $model.Model
}
catch
{
$Script:model = "ERROR - Could not determine"
$Script:QC = $false
}
#--------------------------------------------------------------------------------------
#getting CPU with error control
try{
$cpu = Get-CimInstance CIM_Processor
$Script:cpu = $cpu.Name
}
catch
{
$Script:cpu = "ERROR - Could not determine"
$Script:QC = $false
}
#--------------------------------------------------------------------------------------
#Get Operating System Info
try{
$sOS =Get-WmiObject -class Win32_OperatingSystem
foreach($sProperty in $sOS){
$Script:OS = $sProperty.Caption
}
}
catch
{
$Script:OS = "ERROR - Could not determine"
$Script:QC = $false
}
#--------------------------------------------------------------------------------------
#Getting the RAM with error control
try{
$RAM = Get-CimInstance CIM_ComputerSystem
$Script:ram = $RAM.TotalPhysicalMemory/1GB
}
catch
{
$Script:ram = "ERROR - Could not determine"
$Script:QC = $false
}
#--------------------------------------------------------------------------------------
}
以上是关于powershell 获取已加载的常规设备信息的主要内容,如果未能解决你的问题,请参考以下文章