Skip to content

Enable-DbaFilestream - Report what the WMI provider actually returned - #10525

Merged
potatoqualitee merged 1 commit into
developmentfrom
fix-filestream-return-value
Aug 8, 2026
Merged

Enable-DbaFilestream - Report what the WMI provider actually returned#10525
potatoqualitee merged 1 commit into
developmentfrom
fix-filestream-return-value

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Fixes #10524.

The bug

Get-FilestreamReturnValue gated its success message on a constant expression:

{ 2147021885 -or 2147945411 -or 0 } {
    "The requested operation is successful. ..."
}

$Value never appears in it. 2147021885 -or 2147945411 -or 0 is just $true, so the clause matched every code. And because switch runs every matching clause without a break, that produced three separate problems:

Return code Before After
2147024891 "Access denied" Access denied and the success message Failure / Access denied
any unlisted code only the success message, raw value lost Unknown, raw value kept
0 / the two 21470… codes success Success

default was unreachable, so an unrecognized code could never fall through to report its own value.

Enable-DbaFilestream then discarded even that, surfacing the value only when -Force was absent — and -Force is the documented non-interactive path used by the examples and every test. A refused call produced no warning, no error, and an unchanged instance.

How it showed up

On a ci-azure RESTART runner while working #10522, setting FILESTREAM level 2 left the instance at level 1 on every attempt with nothing reported. The instance came back with ServiceShareName still set to the instance-name fallback rather than the share name that was passed, so the call had changed nothing at all — and the return code that would have said why was gone.

The change

Get-FilestreamReturnValue moves into its own file under private/functions/ so it can be tested, and returns ReturnValue, Category and Message. Category is Success, Failure or Unknown.

Codes in neither list are reported as Unknown with the raw value rather than guessed at in either direction — assuming success hides a refusal, assuming failure invents an error the provider never reported. A null return value is Unknown for the same reason, since switch enters no clause at all for $null.

Enable-DbaFilestream now stops on a documented refusal and warns on an unrecognized code, both regardless of -Force. -Force should mean "do not prompt", not "do not report errors". The existing warning that changes need a service restart is unchanged.

Testing

Five unit tests cover each category, plus two edge cases worth calling out:

  • a null return valueswitch ($null) enters no clause, so without an explicit guard this reported Failure for a call that never returned anything
  • numeric typeInvoke-CimMethod hands back a UInt32, so a comparison that only matched Int32 would push every real call down the unknown path

Against a live lab, all three filestream commands still pass: Enable-DbaFilestream 3 integration tests (levels 1 and 2 and the ShareName warning), Disable-DbaFilestream and Get-DbaFilestream unchanged. Repo compliance and structure gates: 0 failures.

Note

This does not by itself fix the level 2 failure on ci-azure — it makes the provider's reason visible so that can finally be diagnosed. The level 2 test is skipped in #10522 with a pointer to #10524; once this merges it can be unskipped to read the real return code.

🤖 Generated with Claude Code

Get-FilestreamReturnValue gated its success message on
{ 2147021885 -or 2147945411 -or 0 }, a constant expression that is always true,
so it matched every return code. Since switch runs every matching clause without
a break, this had three effects:

- a documented refusal came back as its own message AND the success message
- default became unreachable, so an unrecognized code was reported as a plain
  success and its raw value was lost
- no caller could tell success from failure by looking at the return value

Enable-DbaFilestream then dropped even that, because it only surfaced the value
when -Force was absent, and -Force is the documented non-interactive path that
the examples and every test use. A refused call therefore produced no warning,
no error, and an unchanged instance.

Seen on ci-azure while working #10522: setting FileStream level 2 left the
instance at level 1 on every attempt with nothing reported, and the return code
that would have said why was gone.

The function moves to its own file so it can be tested, and now returns
ReturnValue, Category and Message. Category is Success, Failure or Unknown -
codes in neither list are reported as Unknown with the raw value rather than
guessed at in either direction, since assuming success hides a refusal and
assuming failure invents an error the provider never reported. A null return
value is Unknown too, because switch does not enter any clause for null.

Enable-DbaFilestream stops on a documented refusal and warns on an unrecognized
code, both regardless of -Force. -Force means do not prompt, not do not report
errors. The existing warning about changes needing a restart is unchanged.

Fixes #10524

(do Enable-DbaFilestream, Disable-DbaFilestream, Get-DbaFilestream)
@potatoqualitee

Copy link
Copy Markdown
Member

I really like this, thank you

@potatoqualitee
potatoqualitee merged commit 6db5559 into development Aug 8, 2026
21 checks passed
@potatoqualitee
potatoqualitee deleted the fix-filestream-return-value branch August 8, 2026 07:54
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.

Set-FileSystemSetting - Get-FilestreamReturnValue reports every WMI return code as success

2 participants