私は、Windows 2008-2016サーバのリストからpowershellを使用してドライブ情報を取得しようとしています。情報を取得するためのコードがありますが、リモートではなく、サーバー名のtxtファイルからではなく、自分のローカルシステムからのみ取得します。以下は私のコードです。リモートサーバーからのデータ収集powershellを使用して
$Computers = @()
Function Get-DriveInfo {
Get-WmiObject Win32_DiskDrive | ForEach-Object {
$disk = $_
$partitions = "ASSOCIATORS OF " +
"{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
"WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Get-WmiObject -Query $partitions | ForEach-Object {
$partition = $_
$drives = "ASSOCIATORS OF " +
"{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | ForEach-Object {
New-Object -Type PSCustomObject -Property @{
Disk = $disk.DeviceID
DiskSize = '{0:d} GB' -f [int]($disk.Size/1GB)
DiskModel = $disk.Model # Unique for Physical, VM, and SAN
Partition = $partition.Name
RawSize = '{0:d} GB' -f [int]($partition.Size/1GB)
DriveLetter = $_.DeviceID
VolumeName = $_.VolumeName
Size = '{0:d} GB' -f [int]($_.Size/1GB)
FreeSpace = '{0:d} GB' -f [int]($_.FreeSpace/1GB)
}
}
}
}
}
$Computers += Get-DriveInfo $ComputerName
Write-Output $Computers
また、私はちょうどサーバー名
server1
server2
server3
私はこれを行うに800+のサーバーを持っているを示していますtxtファイルを持っています。データを取得したら、結果をダンプするための最良のファイルの種類が不明です。私はjsonファイルを使うのは良いアイデアかもしれないと言われましたが、以前はjsonを使用していませんでした。基本的に私は私がこの順に結果を表示できるように検索可能オブジェクトを作成しようとしています:
DiskModel
Partition
FreeSpace
Size
'は、Get-WmiObject'に –