Skip to content

Get-DbaDiskSpace - Make Unit work and clean up the two other dead parameters - #10611

Open
andreasjordan wants to merge 1 commit into
developmentfrom
fix-getdbadiskspace-dead-parameters
Open

Get-DbaDiskSpace - Make Unit work and clean up the two other dead parameters#10611
andreasjordan wants to merge 1 commit into
developmentfrom
fix-getdbadiskspace-dead-parameters

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Problem

Three parameters of Get-DbaDiskSpace were declared, documented with examples, and never read:

  • -Unit was deprecated in the 2017 rewrite (when the output became self-formatting Size objects), but the parameter, its GB default and its help examples all survived, so -Unit MB silently returned the same display as no parameter at all.
  • -SqlCredential lost its only consumer when -CheckForSql was removed in 2019 (get-dbadiskspace -checksql needs some tlc #5023).
  • -CheckFragmentation lost its DefragAnalysis implementation in the same 2017 rewrite.

What changed

  • -Unit now works. The Size type has a writable per-object display style, so the command sets it on Capacity and Free when -Unit is bound: -Unit MB displays 1,907,348.63 MB where the default displays 1.82 TB. The underlying values are unchanged and all SizeIn*/FreeIn* properties remain available. PB is dropped from the ValidateSet because the SizeStyle enum does not offer it, and the never-applied GB default is dropped so the default display stays dynamic — both exactly as the command has actually behaved for nine years.
  • -SqlCredential is removed. A deprecation warning was not an option here: the test guide and many environments set a wildcard *:SqlCredential default via $PSDefaultParameterValues, which binds the parameter on every call and would warn for everyone.
  • -CheckFragmentation stops with a message (the Get-DbaDbBackupHistory -AgCheck precedent), since silently returning results without the requested fragmentation data misleads the caller.

Help and .OUTPUTS updated accordingly.

Tests

Parameter validation updated; new tests assert -Unit MB changes the displayed unit without changing the values, and that -CheckFragmentation returns nothing and warns. Verified locally: all three fail against the old code (-Unit MB displaying 49.47 GB is exactly the reported symptom) and the file passes 6/6 with the fix.

Found by @greenmtnsun via static analysis, reported in #10607.

🤖 Generated with Claude Code

…ameters

Unit was deprecated in 2017 when the output became Size objects, but
the parameter, its default and its examples all survived, so -Unit MB
silently returned the same display as no parameter at all. The Size
objects have a per-object display style, so Unit now sets that style
on Capacity and Free: the display follows the requested unit and the
underlying values are unchanged. PB is dropped from the ValidateSet
because the SizeStyle enum does not offer it, and the never-applied
GB default is dropped so the default display stays dynamic.

SqlCredential lost its only consumer when CheckForSql was removed in
2019 (#5023) and is removed; a warning instead would fire for everyone
who sets a wildcard *:SqlCredential default. CheckFragmentation lost
its implementation in the 2017 rewrite and now stops with a message,
following the Get-DbaDbBackupHistory -AgCheck precedent.

Found via static analysis by @greenmtnsun in #10607.

(do Get-DbaDiskSpace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant