tests/Test-HostDriveBlockSize.ps1
function Test-HostDriveBlockSize { [CmdletBinding()] param ( [parameter()][string] $TestName = "Test-HostDriveBlockSize", [parameter()][string] $TestGroup = "configuration", [parameter()][string] $Description = "Validate disk format block size", [parameter()][hashtable] $ScriptParams ) try { [System.Collections.Generic.List[PSObject]]$tempdata = @() # for detailed test output to return if needed $stat = "PASS" $msg = "Success" $bsize = 65536 if ($ScriptParams.Credential) { $cs = New-CimSession -Credential $ScriptParams.Credential -Authentication Negotiate -ComputerName $ScriptParams.ComputerName $vols = Get-CimInstance "Win32_Volume" -CimSession $cs -Filter "DriveType = 3" | Where-Object {![string]::IsNullOrEmpty($_.DriveLetter)} } else { $vols = Get-CimInstance "Win32_Volume" -ComputerName $ScriptParams.ComputerName -Filter "DriveType = 3" | Where-Object {![string]::IsNullOrEmpty($_.DriveLetter)} } $vols | Foreach-Object { if ($_.BlockSize -eq $bsize) {$res = 'PASS'} else {$res = 'FAIL'} $tempdata.Add([pscustomobject]@{ Computer = $ScriptParams.ComputerName Drive = $_.DriveLetter Result = $res }) } } catch { $stat = 'ERROR' $msg = $_.Exception.Message -join ';' } finally { if ($cs) { $cs.Close(); $cs = $null } Write-Output $([pscustomobject]@{ TestName = $TestName TestGroup = $TestGroup TestData = $tempdata Description = $Description Status = $stat Message = $msg Credential = $(if($ScriptParams.Credential){$($ScriptParams.Credential).UserName} else { $env:USERNAME }) }) } } |