windows 如何使用powershell远程收集系统监控信息?

r7knjye2  于 2023-02-05  发布在  Windows
关注(0)|答案(1)|浏览(204)

我有代码远程收集系统信息,并创建一个csv文件,如下,

Param(
  [Parameter(Mandatory=$true, position=0)][string]$infile,
  [Parameter(Mandatory=$true, position=1)][string]$outfile
)

#Column header in input CSV file that contains the host name 
$ColumnHeader = "ComputerName"
$HostList = import-csv $infile | select-object $ColumnHeader
$out = @()

foreach($object in $HostList) {
    
    $os = Get-WmiObject -computername $object.("ComputerName") -class win32_operatingsystem
    $vol = Get-WmiObject -computername $object.("ComputerName") -class Win32_Volume
    $net = Get-WmiObject -computername $object.("ComputerName") -class Win32_NetworkAdapterConfiguration | where-object { $_.IPAddress -ne $null }

    $DeviceInfo= @{}
    $DeviceInfo.add("Operating System", $os.name.split("|")[0])
    $DeviceInfo.add("Version", $os.Version)
    $DeviceInfo.add("Architecture", $os.OSArchitecture)
    $DeviceInfo.add("Serial Number", $os.SerialNumber)
    $DeviceInfo.add("Organization", $os.Organization)
    $DeviceInfo.add("Disk Capacity", "$([math]::floor($vol.Capacity/ (1024 * 1024 * 1024 )) )" + " GB" )
    $DeviceInfo.add("Free Capacity", "$([math]::floor($vol.FreeSpace/ (1024 * 1024 * 1024 )))" + " GB" )
    $DeviceInfo.add("System Name", $vol.SystemName)
    $DeviceInfo.add("File System", $vol.FileSystem)
    $DeviceInfo.add("IP Address", ($net.IPAddress -join (", ")))
    $DeviceInfo.add("Subnet", ($net.IPSubnet  -join (", ")))
    $DeviceInfo.add("MAC Address", $net.MACAddress )

    $out += New-Object PSObject -Property $DeviceInfo | Select-Object `
              "System Name", "Organization", "Serial Number","Operating System", `
              "Version","Architecture","File System","Disk Capacity", `
              "Free Capacity","MAC Address","IP Address","Subnet"

    Write-Verbose ($out | Out-String) -Verbose             
    $out | Export-CSV $outfile -NoTypeInformation
 }

我有一个脚本来获取监视器信息

function Decode {
    If ($args[0] -is [System.Array]) {
        [System.Text.Encoding]::ASCII.GetString($args[0])
    }
    Else {
        "Not Found"
    }
}

ForEach ($Monitor in Get-WmiObject WmiMonitorID -Namespace root\wmi) {  
    $Manufacturer = Decode $Monitor.ManufacturerName -notmatch 0
    $Name = Decode $Monitor.UserFriendlyName -notmatch 0
    $Serial = Decode $Monitor.SerialNumberID -notmatch 0
    $ManufactureWeek = (Get-WmiObject WmiMonitorID -Namespace root\wmi).WeekofManufacture
    $ManufactureYear = (Get-WmiObject WmiMonitorID -Namespace root\wmi).YearOfManufacture
    
    echo "Manufacturer: $Manufacturer`nName: $Name`nSerial Number: $Serial"
    echo "Week of Manufacture: $ManufactureWeek"
    echo "Year of Manufacture: $ManufactureYear"
}

我怎样才能把这些代码组合起来远程获取监控信息,我怎样才能远程获取监控信息?????????

z9smfwbn

z9smfwbn1#

您也可以更新监视器脚本。如果有多个监视器,它将无法正常工作。

function Decode {
    If ($args[0] -is [System.Array]) {
        [System.Text.Encoding]::ASCII.GetString($args[0])
    }
    Else {
        "Not Found"
    }
}

ForEach ($Monitor in Get-WmiObject WmiMonitorID -Namespace root\wmi) {  
    $Manufacturer = Decode $Monitor.ManufacturerName -notmatch 0
    $Name = Decode $Monitor.UserFriendlyName -notmatch 0
    $Serial = Decode $Monitor.SerialNumberID -notmatch 0
    $ManufactureWeek = $Monitor.WeekofManufacture
    $ManufactureYear = $Monitor.YearOfManufacture
    
    echo "Manufacturer: $Manufacturer`nName: $Name`nSerial Number: $Serial"
    echo "Week of Manufacture: $ManufactureWeek"
    echo "Year of Manufacture: $ManufactureYear"
}

相关问题