2017-05-11 4 views
-1

コンピュータのリストのコンピュータ情報を取得してテーブルに追加しようとしています。どのように私はハッシュテーブルからデータを取得し、1つのテーブルに追加することができます混乱の種類。以下は私がこれまで持っていたコードです。どんな援助も感謝します!複数のハッシュテーブルの値をPowershellのテーブルでフォーマットする必要があります

$name = Get-Content .\computers.txt 


foreach($c in $Name){ 


$test = Test-Connection -ComputerName $c -Count 1 -Quiet 

if($test -eq $true) 
{ 
$os = Get-WmiObject -Class win32_operatingsystem -ComputerName $c -ErrorAction SilentlyContinue 
$cs = Get-WmiObject -Class win32_computersystem -ComputerName $c -ErrorAction SilentlyContinue 
$pr = Get-WmiObject -Class win32_processor -ComputerName  $c -ErrorAction SilentlyContinue 
$bs = Get-WmiObject -Class win32_bios -ComputerName $c -ErrorAction SilentlyContinue 
$ps = Get-WmiObject -Class win32_processor -ComputerName  $c -ErrorAction SilentlyContinue 
$us = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $c -ErrorAction SilentlyContinue 



[hashtable]$osProperties = @{ 
    ‘Model’=$cs.model; 
    ‘Manufacturer’=$cs.manufacturer; 
    ‘RAM’=$cs.totalphysicalmemory/1GB -as [int] ; 
    ‘Cores’=$cs.numberoflogicalprocessors; 
    ‘SystemType’=$cs.SystemType 
    ‘CPU’=$pr.name; 
    ‘Serial’=$bs.serialnumber 
    ‘OSVersion’=$os.caption; 
    'User'=$us.username; 
    } 



    #$obj = New-Object -TypeName PSCustomObject -Property $osProperties | select Manufacturer, Model, Serial, OSVersion, CPU, Cores, @{name="Ram (GB)";expression={$($_.Ram)}}, User | ft 

    } 




else{ 
$c=$Null 
} 

} 

答えて

0

開始するには、一度に1台ずつコンピュータを実行しないでください。あなたはサイクルを無駄にしています...

$name = Get-Content .\computers.txt 
#Get a list of online servers 
$online = Test-Connection $name -count 1 -ea 4|% Address 
#Define what we want to do on those servers 
$ScriptBlock = { 
    $os = Get-WmiObject -Class win32_operatingsystem -ErrorAction SilentlyContinue 
    $cs = Get-WmiObject -Class win32_computersystem -ErrorAction SilentlyContinue 
    $pr = Get-WmiObject -Class win32_processor -ErrorAction SilentlyContinue 
    $bs = Get-WmiObject -Class win32_bios -ErrorAction SilentlyContinue 
    $ps = Get-WmiObject -Class win32_processor -ErrorAction SilentlyContinue 

    [PSCustomObject]@{ 
     ‘Model’=$cs.model; 
     ‘Manufacturer’=$cs.manufacturer; 
     ‘RAM’=$cs.totalphysicalmemory/1GB -as [int] ; 
     ‘Cores’=$cs.numberoflogicalprocessors; 
     ‘SystemType’=$cs.SystemType 
     ‘CPU’=$pr.name; 
     ‘Serial’=$bs.serialnumber 
     ‘OSVersion’=$os.caption; 
     'User'=$cs.username; 
    } 
} 
#Execute the scriptblock on each server, returning results as objects 
$Results = Invoke-Command -scriptblock $ScriptBlock -ComputerName $Online 
#Display those objects as a table 
$Results | FT 
関連する問題