[CmdletBinding()] param( [string]$Csv ) $ErrorActionPreference = 'Stop' $disks = @(Get-Disk -ErrorAction Stop | Select-Object Number, FriendlyName, PartitionStyle, OperationalStatus, HealthStatus, @{Name = 'SizeGB'; Expression = { [math]::Round($_.Size / 1GB, 2) }} | Sort-Object Number) $rows = foreach ($partition in Get-Partition -ErrorAction Stop) { $letter = [string]$partition.DriveLetter if ($letter -notmatch '^[A-Za-z]$') { $letter = '' } $volume = $null if ($letter) { try { $volume = Get-Volume -DriveLetter $letter -ErrorAction Stop } catch { $volume = $null } } [pscustomobject]@{ Disk = $partition.DiskNumber Partition = $partition.PartitionNumber Letter = $letter Type = $partition.Type SizeGB = [math]::Round($partition.Size / 1GB, 2) OffsetGB = [math]::Round($partition.Offset / 1GB, 2) FileSystem = if ($volume) { $volume.FileSystem } else { '' } Label = if ($volume) { $volume.FileSystemLabel } else { '' } FreeGB = if ($volume) { [math]::Round($volume.FreeSpace / 1GB, 2) } else { $null } Health = if ($volume) { $volume.HealthStatus } else { '' } IsBoot = $partition.IsBoot IsSystem = $partition.IsSystem IsReadOnly = $partition.IsReadOnly } } $rows = @($rows | Sort-Object Disk, Partition) Write-Host 'Физические диски:' $disks | Format-Table -AutoSize Write-Host 'Разделы и тома:' $rows | Format-Table -AutoSize if ($Csv) { $parent = Split-Path -Parent $Csv if ($parent -and -not (Test-Path -LiteralPath $parent)) { New-Item -ItemType Directory -Path $parent | Out-Null } $rows | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $Csv" } Write-Host 'Диски и разделы только прочитаны, операции с хранилищем не выполнялись.'