Depolama aygıtlarında dosya ve klasörlerin fiziksel yer kaplama biçimi, yalnızca bayt cinsinden ifade edilen boyut değeriyle tam olarak anlaşılamaz. Bir dosya sistemi, veriyi diskin sektör adı verilen sabit boyutlu birimler hâlinde tahsis eder; dolayısıyla bir nesnenin gerçek disk üzerindeki izdüşümü, sektör sayısı cinsinden ifade edildiğinde daha somut bir anlam kazanır. Bu çalışmada, kullanıcının belirttiği bir dosya/klasör yolu veya doğrudan bir boyut değeri üzerinden toplam sektör sayısını hesaplayan ve bu değeri belirli eşiklere göre Small / Medium / Large / Huge kategorilerinden birine atayan bir Windows PowerShell (.ps1) betiğinin tasarım süreci ve teknik gerekçeleri ele alınmaktadır.
Girdi Modelleri
Betik, kullanıcıya iki farklı girdi biçimi sunmaktadır:

Sektör Boyutunun Otomatik Tespiti
Betiğin temel özgünlüğü, sektör boyutunu sabit bir varsayım (örneğin klasik 512 bayt) olarak almak yerine, hedef diskin gerçek biçimlendirme yapısından dinamik olarak okumasıdır.
Bu işlem iki adımda gerçekleşir:
Get-Partition -DriveLetter ile ilgili sürücü harfinin bağlı olduğu fiziksel disk numarası tespit edilir.
Get-CimInstance -ClassName Win32_DiskDrive ile o diskin BytesPerSector özelliği okunur.
Bu yaklaşım, SSD/HDD ayrımı gözetmeksizin, gelişmiş format (4K native) disklerle klasik 512 baytlık sektör yapısına sahip diskler arasındaki farkı doğru yansıtır. Kullanıcı, path üzerinden otomatik çıkarımı tercih edebileceği gibi, sürücü harfini elle belirterek farklı bir diskin sektör yapısını da zorlayabilir./değiştirebilir.
Sınıflandırma Eşik Modları
Sektör sayısının anlamlı bir kategoriye dönüştürülmesi için üç farklı eşik stratejisi tasarlanmıştır:

Etkileşimli Menü Katmanı
Betik, parametre verilmeden çalıştırıldığında klasik numaralı bir menüye düşer; bu, komut satırı sözdizimini bilmeyen veya hızlıca tek seferlik bir ölçüm yapmak isteyen kullanıcılar için tasarlanmıştır. Aynı çekirdek fonksiyon, hem doğrudan parametre geçişiyle (-Path, -SizeMB vb.) hem de menüden toplanan girdilerle çağrılabildiği için, iki kullanım biçimi arasında herhangi bir davranış farkı oluşmaz — yalnızca girdi toplama şekli değişir.
PowerShell Sürüm Uyumluluğu
Betik, hem Windows PowerShell 5.1 hem de PowerShell 7.x ile çalışacak şekilde tasarlanmıştır; bu nedenle yalnızca PS 7+'ya özgü sözdizimsel yapılar (örneğin üçlü operatör ?: veya null-coalescing ??) yerine klasik if/elseif/else yapıları tercih edilmiştir.
Bu tasarladığım (tamamen bilimsel meraktan) betik, bir dosya veya klasörün diskteki gerçek yer kaplama karşılığını sektör düzeyinde somutlaştırırken, sabit varsayımlar yerine hedef diskin kendi fiziksel biçimlendirme bilgisini kullanarak daha doğru sonuçlar üretmektedir. Fixed, Custom ve Dynamic olmak üzere üç farklı sınıflandırma stratejisinin bir arada sunulması, betiğin hem genel kullanım hem de disk kapasitesine özgü ölçek gerektiren senaryolarda esnek biçimde kullanılabilmesini sağlamaktadır. Ayrıca komut satırı ve etkileşimli menü seçeneklerinin aynı çekirdek üzerinde birleştirilmesi, betiği hem ileri düzey kullanıcılar hem de hızlı/tek seferlik ölçüm yapmak isteyenler için erişilebilir kılmaktadır.
BETİK KULLANICI NOTLARI :
Örnek A: İleri düzey kullanıcı — komut satırı (parametreyle, tek satır)
Kod: Tümünü seç
PS D:\Scripts> .\Disk-SectorSizeClassifier.ps1 -Path "D:\OYUNLAR\Steam\RDR2" -ThresholdMode Dynamic
===== Disk Size / Sector Classification Report =====
Target : D:\OYUNLAR\Steam\RDR2
Drive used for lookup : D:
Total size (bytes) : 154.618.822.656
Total size (MB) : 147.456,00
Sector size (bytes) : 512
Sector count : 302.024.264
Threshold mode : Dynamic
Small limit (MB) : 9.536,74
Medium limit (MB) : 95.367,43
Large limit (MB) : 286.102,29
Classification : Large
======================================================
Press ENTER to exit:Örnek B: Hızlı/tek seferlik ölçüm — etkileşimli menü
Kod: Tümünü seç
====================================================
Disk Size / Sector Classification - Main Menu
====================================================
1) Measure a file or folder (Path)
2) Enter a direct size in MB
0) Exit
Select an option: 1
Enter the full path of the file or folder: D:\OYUNLAR\Steam\RDR2
Enter drive letter for sector lookup (leave empty to auto-detect from path):
Classification threshold mode:
1) Fixed (100 MB / 1 GB / 10 GB)
2) Custom (you define the limits)
3) Dynamic (proportional to total disk capacity)
Select an option: 3
===== Disk Size / Sector Classification Report =====
Target : D:\OYUNLAR\Steam\RDR2
Drive used for lookup : D:
Total size (bytes) : 154.618.822.656
Total size (MB) : 147.456,00
Sector size (bytes) : 512
Sector count : 302.024.264
Threshold mode : Dynamic
Small limit (MB) : 9.536,74
Medium limit (MB) : 95.367,43
Large limit (MB) : 286.102,29
Classification : Large
======================================================
Press ENTER to return to the menu:EK NOT: YARDIM (HELP) BİLGİSİ
Betik, standart PowerShell yardım sistemine uyumlu olarak Comment-Based Help bloğuyla belgelenmiştir. Bu sayede kullanıcı, betiğin tüm parametrelerini ve kullanım örneklerini PowerShell konsolundan doğrudan sorgulayabilir:
Kod: Tümünü seç
PS D:\Scripts> Get-Help .\Disk-SectorSizeClassifier.ps1 -FullKod: Tümünü seç
PS D:\Scripts> Get-Help .\Disk-SectorSizeClassifier.ps1 -Examples
Komut Çıktısı :
Kod: Tümünü seç
PS C:\Users\TRWE_2012\Masaüstü> Get-Help .\Disk-SectorSizeClassifier.ps1 -Examples
Do you want to run Update-Help? The Update-Help cmdlet downloads the most current Help files for Windows PowerShell modules, and installs them on your computer. For more information about the Update-Help cmdlet, see https:/go.microsoft.com/fwlink/?LinkId=210614. [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
NAME
C:\Users\TRWE_2012\Masaüstü\Disk-SectorSizeClassifier.ps1
SYNOPSIS
Calculates the total disk size of a file or folder (or a directly supplied size)
in disk sectors, and classifies it as Small, Medium, Large, or Huge.
-------------------------- EXAMPLE 1 --------------------------
PS C:\>.\Disk-SectorSizeClassifier.ps1
(Opens the interactive menu.)
-------------------------- EXAMPLE 2 --------------------------
PS C:\>.\Disk-SectorSizeClassifier.ps1 -Path "D:\Games\SomeGame"
-------------------------- EXAMPLE 3 --------------------------
PS C:\>.\Disk-SectorSizeClassifier.ps1 -SizeMB 2500 -DriveLetter D -ThresholdMode Dynamic
-------------------------- EXAMPLE 4 --------------------------
PS C:\>.\Disk-SectorSizeClassifier.ps1 -Path "C:\Data" -ThresholdMode Custom -SmallMaxMB 50 -MediumMaxMB 500 -Large
MaxMB 5000
PS C:\Users\TRWE_2012\Masaüstü>
Parametre Referans Tablosu

Yukarıdaki tabloya göre örnekler :
Kod: Tümünü seç
.\Disk-SectorSizeClassifier.ps1 -Path "D:\Games\SomeGame"Kod: Tümünü seç
.\Disk-SectorSizeClassifier.ps1 -SizeMB 2500 -DriveLetter D -ThresholdMode DynamicKod: Tümünü seç
.\Disk-SectorSizeClassifier.ps1 -Path "C:\Data" -ThresholdMode Custom -SmallMaxMB 50 -MediumMaxMB 500 -LargeMaxMB 5000Parametre bilgisini bilmeyen veya hatırlamayan kullanıcılar için betiğin herhangi bir parametre verilmeden (.\Disk-SectorSizeClassifier.ps1) çalıştırılması yeterlidir; bu durumda betik otomatik olarak etkileşimli menüye geçer ve yukarıdaki tabloda listelenen tüm seçenekleri adım adım sorar. Böylece komut satırı sözdizimi bir ön koşul olmaktan çıkar.
Bu kadar bilgilendirme yeter...
Şimdi betiğin içeriğini verelim...
Disk-SectorSizeClassifier.ps1
Kod: Tümünü seç
<#
.SYNOPSIS
Calculates the total disk size of a file or folder (or a directly supplied size)
in disk sectors, and classifies it as Small, Medium, Large, or Huge.
.DESCRIPTION
Two ways to run this script:
1) With parameters (classic command-line usage) - see EXAMPLES below.
2) Without any parameters - an interactive, numbered classic menu opens,
guiding you step by step through all the same options.
Input modes (choose one):
- Path : a file or folder path; total size is calculated automatically.
- SizeMB : a direct size value, expressed in megabytes.
Sector size is auto-detected from the physical/logical formatting of the target
disk (BytesPerSector, via Win32_DiskDrive), unless manually overridden with -SectorSize.
Classification threshold modes (choose one via -ThresholdMode):
- Fixed : built-in default thresholds (100 MB / 1 GB / 10 GB).
- Custom : user-defined thresholds via -SmallMaxMB / -MediumMaxMB / -LargeMaxMB.
- Dynamic : thresholds proportional to the total capacity of the target disk
(1% / 10% / 30% of total volume size).
Compatible with both Windows PowerShell 5.1 and PowerShell 7.x.
.PARAMETER Path
Path to a file or folder whose size will be measured.
.PARAMETER SizeMB
Direct size value in megabytes (used instead of -Path).
.PARAMETER SectorSize
Manual override for sector size in bytes. If omitted, sector size is auto-detected
from the target disk.
.PARAMETER ThresholdMode
Fixed (default), Custom, or Dynamic.
.PARAMETER SmallMaxMB
Upper bound for the "Small" classification, in MB (Custom mode only).
.PARAMETER MediumMaxMB
Upper bound for the "Medium" classification, in MB (Custom mode only).
.PARAMETER LargeMaxMB
Upper bound for the "Large" classification, in MB (Custom mode only).
.PARAMETER DriveLetter
Drive letter used for sector-size auto-detection and for Dynamic threshold mode.
If omitted, it is inferred from -Path, or defaults to C.
.EXAMPLE
.\Disk-SectorSizeClassifier.ps1
(Opens the interactive menu.)
.EXAMPLE
.\Disk-SectorSizeClassifier.ps1 -Path "D:\Games\SomeGame"
.EXAMPLE
.\Disk-SectorSizeClassifier.ps1 -SizeMB 2500 -DriveLetter D -ThresholdMode Dynamic
.EXAMPLE
.\Disk-SectorSizeClassifier.ps1 -Path "C:\Data" -ThresholdMode Custom -SmallMaxMB 50 -MediumMaxMB 500 -LargeMaxMB 5000
#>
[CmdletBinding()]
param(
[string]$Path,
[double]$SizeMB = 0,
[int]$SectorSize = 0,
[ValidateSet("Fixed", "Custom", "Dynamic")]
[string]$ThresholdMode = "Fixed",
[double]$SmallMaxMB = 100,
[double]$MediumMaxMB = 1024,
[double]$LargeMaxMB = 10240,
[string]$DriveLetter
)
function Get-DiskSectorSize {
param([string]$TargetDriveLetter)
try {
$letter = $TargetDriveLetter.TrimEnd(":")
$partition = Get-Partition -DriveLetter $letter -ErrorAction Stop
$disk = Get-CimInstance -ClassName Win32_DiskDrive -ErrorAction Stop |
Where-Object { $_.Index -eq $partition.DiskNumber }
if ($disk -and $disk.BytesPerSector) {
return [int]$disk.BytesPerSector
}
}
catch {
Write-Warning "Could not auto-detect sector size. Falling back to 512 bytes."
}
return 512
}
function Get-DiskTotalCapacityBytes {
param([string]$TargetDriveLetter)
try {
$letter = $TargetDriveLetter.TrimEnd(":")
$volume = Get-Volume -DriveLetter $letter -ErrorAction Stop
return [int64]$volume.Size
}
catch {
Write-Warning "Could not read total disk capacity. Dynamic mode will fall back to Fixed thresholds."
return $null
}
}
function Exit-WithPause {
param([int]$Code = 0)
Read-Host "`nPress ENTER to exit"
exit $Code
}
function Invoke-Classification {
param(
[string]$Path,
[double]$SizeMB = 0,
[int]$SectorSize = 0,
[string]$ThresholdMode = "Fixed",
[double]$SmallMaxMB = 100,
[double]$MediumMaxMB = 1024,
[double]$LargeMaxMB = 10240,
[string]$DriveLetter
)
$totalBytes = 0
$resolvedDriveLetter = $DriveLetter
$targetDescription = ""
if ($Path) {
if (-not (Test-Path -LiteralPath $Path)) {
Write-Error "The specified path does not exist: $Path"
return
}
$item = Get-Item -LiteralPath $Path
$targetDescription = $Path
if ($item.PSIsContainer) {
$sum = (Get-ChildItem -LiteralPath $Path -Recurse -File -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
if ($sum) { $totalBytes = $sum } else { $totalBytes = 0 }
}
else {
$totalBytes = $item.Length
}
if (-not $resolvedDriveLetter) {
$resolvedDriveLetter = (Split-Path -Qualifier (Resolve-Path -LiteralPath $Path)).TrimEnd(":")
}
}
elseif ($SizeMB -gt 0) {
$totalBytes = [int64]($SizeMB * 1MB)
$targetDescription = "$SizeMB MB (direct input)"
}
else {
Write-Error "You must provide either a path or a size in MB."
return
}
if (-not $resolvedDriveLetter) {
$resolvedDriveLetter = "C"
}
if (-not $SectorSize -or $SectorSize -le 0) {
$SectorSize = Get-DiskSectorSize -TargetDriveLetter $resolvedDriveLetter
}
$sectorCount = [math]::Ceiling($totalBytes / $SectorSize)
$smallLimitBytes = 0
$mediumLimitBytes = 0
$largeLimitBytes = 0
switch ($ThresholdMode) {
"Fixed" {
$smallLimitBytes = 100MB
$mediumLimitBytes = 1GB
$largeLimitBytes = 10GB
}
"Custom" {
$smallLimitBytes = [int64]($SmallMaxMB * 1MB)
$mediumLimitBytes = [int64]($MediumMaxMB * 1MB)
$largeLimitBytes = [int64]($LargeMaxMB * 1MB)
}
"Dynamic" {
$diskCapacity = Get-DiskTotalCapacityBytes -TargetDriveLetter $resolvedDriveLetter
if ($diskCapacity) {
$smallLimitBytes = $diskCapacity * 0.01
$mediumLimitBytes = $diskCapacity * 0.10
$largeLimitBytes = $diskCapacity * 0.30
}
else {
$smallLimitBytes = 100MB
$mediumLimitBytes = 1GB
$largeLimitBytes = 10GB
}
}
}
$classification = "Huge"
if ($totalBytes -lt $smallLimitBytes) {
$classification = "Small"
}
elseif ($totalBytes -lt $mediumLimitBytes) {
$classification = "Medium"
}
elseif ($totalBytes -lt $largeLimitBytes) {
$classification = "Large"
}
Write-Host ""
Write-Host "===== Disk Size / Sector Classification Report ====="
Write-Host ("Target : {0}" -f $targetDescription)
Write-Host ("Drive used for lookup : {0}:" -f $resolvedDriveLetter)
Write-Host ("Total size (bytes) : {0:N0}" -f $totalBytes)
Write-Host ("Total size (MB) : {0:N2}" -f ($totalBytes / 1MB))
Write-Host ("Sector size (bytes) : {0}" -f $SectorSize)
Write-Host ("Sector count : {0:N0}" -f $sectorCount)
Write-Host ("Threshold mode : {0}" -f $ThresholdMode)
Write-Host ("Small limit (MB) : {0:N2}" -f ($smallLimitBytes / 1MB))
Write-Host ("Medium limit (MB) : {0:N2}" -f ($mediumLimitBytes / 1MB))
Write-Host ("Large limit (MB) : {0:N2}" -f ($largeLimitBytes / 1MB))
Write-Host ("Classification : {0}" -f $classification)
Write-Host "======================================================"
Write-Host ""
}
function Read-InteractiveThresholdMode {
Write-Host ""
Write-Host "Classification threshold mode:"
Write-Host " 1) Fixed (100 MB / 1 GB / 10 GB)"
Write-Host " 2) Custom (you define the limits)"
Write-Host " 3) Dynamic (proportional to total disk capacity)"
$modeChoice = Read-Host "Select an option"
switch ($modeChoice) {
"2" { return "Custom" }
"3" { return "Dynamic" }
default { return "Fixed" }
}
}
function Show-InteractiveMenu {
$continue = $true
while ($continue) {
Clear-Host
Write-Host "===================================================="
Write-Host " Disk Size / Sector Classification - Main Menu"
Write-Host "===================================================="
Write-Host "1) Measure a file or folder (Path)"
Write-Host "2) Enter a direct size in MB"
Write-Host "0) Exit"
Write-Host ""
$choice = Read-Host "Select an option"
switch ($choice) {
"1" {
$inputPath = Read-Host "Enter the full path of the file or folder"
$inputDrive = Read-Host "Enter drive letter for sector lookup (leave empty to auto-detect from path)"
$thresholdMode = Read-InteractiveThresholdMode
$smallMB = 100; $mediumMB = 1024; $largeMB = 10240
if ($thresholdMode -eq "Custom") {
$smallMB = [double](Read-Host "Small classification upper limit (MB)")
$mediumMB = [double](Read-Host "Medium classification upper limit (MB)")
$largeMB = [double](Read-Host "Large classification upper limit (MB)")
}
Invoke-Classification -Path $inputPath -DriveLetter $inputDrive -ThresholdMode $thresholdMode `
-SmallMaxMB $smallMB -MediumMaxMB $mediumMB -LargeMaxMB $largeMB
Read-Host "`nPress ENTER to return to the menu"
}
"2" {
$inputSize = Read-Host "Enter size in MB"
$inputDrive = Read-Host "Enter drive letter for sector lookup (default: C)"
if (-not $inputDrive) { $inputDrive = "C" }
$thresholdMode = Read-InteractiveThresholdMode
$smallMB = 100; $mediumMB = 1024; $largeMB = 10240
if ($thresholdMode -eq "Custom") {
$smallMB = [double](Read-Host "Small classification upper limit (MB)")
$mediumMB = [double](Read-Host "Medium classification upper limit (MB)")
$largeMB = [double](Read-Host "Large classification upper limit (MB)")
}
Invoke-Classification -SizeMB ([double]$inputSize) -DriveLetter $inputDrive -ThresholdMode $thresholdMode `
-SmallMaxMB $smallMB -MediumMaxMB $mediumMB -LargeMaxMB $largeMB
Read-Host "`nPress ENTER to return to the menu"
}
"0" {
$continue = $false
}
default {
Write-Host "Invalid selection." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
}
}
}
# --- Entry point ---
if ($PSBoundParameters.Count -eq 0) {
Show-InteractiveMenu
}
else {
Invoke-Classification -Path $Path -SizeMB $SizeMB -SectorSize $SectorSize -ThresholdMode $ThresholdMode `
-SmallMaxMB $SmallMaxMB -MediumMaxMB $MediumMaxMB -LargeMaxMB $LargeMaxMB -DriveLetter $DriveLetter
Exit-WithPause -Code 0
}



NOT :
Microsoft ve GNU/Linux ISO hash sağlamasını da sektör bayt üzerinden de yapabilirsiniz.
1.Önce ISO'NUN hash kaydını bulursunuz.
2.Sonra bu betikle toplam sektör sayısını bulursunuz.
3. (1) + (2) = Sağlam ISO kaydını birleştirmiş olursunuz.
Google SEO HasTag's: (Google Bot(örümceklerin) okuması için buraya yazıldı.Böylece forum'un Google Sıralamadaki yeri yükselsin... TRWE_2012)
#PowerShellScripting
#DiskSectorSize
#StorageAnalysis
#FileSizeClassification
#WindowsAdministration
#SSDvsHDD
#DiskManagementTools
#SystemAdministrationScripts
------------------------------------------------------------------------------------------------------------
PowerShell Hakkında İnteraktif Kitap :
https://learn.microsoft.com/tr-tr/power ... rshell-7.6
-------------------------------------------------------------------------------------------------------------
Hazır Windows Betikleri :
https://www.powershellgallery.com/packages
-------------------------------------------------------------------------------------------------------------

