2017-11-23 16 views
0

複数の配列にわたってDCの情報を取得します。Powershell pscustomobjectの内部で結果の配列を展開します

十分にわかりやすいが、所望の形式で返すように修正されたディスクオブジェクトを取得問題持つ:私はスクリプトを実行すると、私は次のような出力を得る

$alldomains = @("domain1.com","domain2.com","domain3.com","domain4.com") 
$password = Read-Host "Enter $domain password" -AsSecureString  

Foreach ($domain in $alldomains) { 

    $creds = new-object -typename System.Management.Automation.PSCredential -argumentlist "$domain\$env:USERNAME", $password 
    $dclist = (Get-ADForest $domain -Credential $creds).Domains | %{(Get-ADDomainController -Filter * -Server $_).hostname} 
     Foreach ($DC in $dclist) { 
      $cpu = gwmi win32_processor -ComputerName $DC -Credential $creds 
      $disk = @(gwmi win32_logicaldisk -ComputerName $DC -Credential $creds | ? {$_.drivetype -eq '3'} | select @{N='Drive Letter';E={$_.caption}},description,drivetype,volumename,@{N='Size (GB)';E={[math]::Round(($_.size/1GB),2)}}) 

      New-Object PSCustomObject -Property @{ 
       'Domain'=$domain; 
       'Hostname'=$DC; 
       'CPU Model'=$cpu.name 
       'CPU Cores'=$cpu.NumberOfCores 
       'CPU Logical Processors'=$cpu.NumberOfLogicalProcessors 
       'Memory (GB)'=$memory.Capacity/1GB 
       'Fixed Disks'=$($disk) 
      }  ormat: 
     } 
} 

を:

.\tsyDCs.ps1 | ft 

CPU Logical Processors Domain       Hostname          CPU Cores CPU Model         Memory (GB) Fixed Disks                    
---------------------- ------       --------          --------- ---------         ----------- -----------                    
        4 Domain1.com DC1.Domain1.com   4 Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=4... 
        4 Domain1.com DC2.Domain1.com   4 Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=4... 
        4 Domain1.com DC3.Domain1.com   4 Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=4... 
        4 Domain1.com DC4.Domain1.com   4 Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=4... 
        12 Domain2.com DC1.Domain2.com   6 Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=1... 
        12 Domain2.com DC2.Domain2.com   6 Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=1... 
        12 Domain2.com DC3.Domain2.com   6 Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=System; Size ... 
        12 Domain2.com DC4.Domain2.com   6 Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=1... 
        2 Domain3.com DC1.Domain3.com   2 Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=9... 
        2 Domain3.com DC2.Domain3.com   2 Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=; Size (GB)=1... 
        12 Domain4.com DC1.Domain4.com   6 Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=System; Size ... 
        12 Domain4.com DC2.Domain4.com   6 Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz   16 {@{Drive Letter=C:; description=Local Fixed Disk; drivetype=3; volumename=System; Size ... 

私が展開することができますどのようにそれらの結果はpscustomobjectを使って取得し、そこに 'テーブル'を埋め込む方法があります。 FTの結果は?

+0

を "目的のフォーマット" とは何ですか?どのようにあなたがそれが欲しいのあなたのポストにいくつかの例を入れて、それが私たちはそれを取得する方法を働くのに役立つか、手でそれをしようとすると、単純な答えがない方法を表示します。 "* FTの結果の中に 'テーブル'を埋め込む方法はありますか?*" - はい。これでやったことは、Fixed Disksプロパティはオブジェクトの配列で、出力はネストされた '行'がデフォルトの書式でどのように見えるかです。 – TessellatingHeckler

+0

現在表示されているtruncatd出力ではなく、すべての情報を示すFixed Disks列が望ましい結果になります。 – J1raya

+1

おそらく、すべての情報を表示するのに十分なスペースがないため、切り捨てられます。データが欠けていて、切り捨てられないようにするには、あなたが何をしたいのかを言う必要があります。それらをPSCustomObjectsにする必要がありますか、それとも文字列にすることができますか?各ディスクに複数の行が必要ですか?他の列はより狭い?より広いコンソール画面?ヘッダーが入ったテーブル?あなたは 'ft -AutoSize'や' ft -Wrap'、あるいはその両方を試しましたか?サーバーに5または20のディスクがある場合はどうなりますか? – TessellatingHeckler

答えて

0

これはそれをやった:

$alldomains = @("domain1.com","domain2.com","domain3.com","domain4.com") 
$password = Read-Host "Enter $domain password" -AsSecureString  

Foreach ($domain in $alldomains) { 

    $creds = new-object -typename System.Management.Automation.PSCredential -argumentlist "$domain\$env:USERNAME", $password 
    $dclist = (Get-ADForest $domain -Credential $creds).Domains | %{(Get-ADDomainController -Filter * -Server $_).hostname} 
     $cpu = gwmi win32_processor -ComputerName $DC -Credential $creds 
     $disklist = @(gwmi win32_logicaldisk -ComputerName $DC -Credential $creds | ? {$_.drivetype -eq '3'} | select @{N='DriveLetter';E={$_.caption}},description,drivetype,volumename,@{N='Size (GB)';E={[math]::Round(($_.size/1GB),2)}}) 
      Foreach ($disk in $disklist) { 
       New-Object PSCustomObject -Property @{ 
        'Domain'=$domain; 
        'Hostname'=$DC; 
        'CPU Model'=$cpu.name 
        'CPU Cores'=$cpu.NumberOfCores 
        'CPU Logical Processors'=$cpu.NumberOfLogicalProcessors 
        'Memory (GB)' = $memory.Capacity/1GB 
        'Drive Letter' = $disk.'DriveLetter' 
        'Volume Name' = $disk.Volumename 
        'Size (GB)' = $disk.'Size (GB)' 
      } 
     }  
    } 
} 
関連する問題