dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Invoke-DbaDbShrink doesn't accept pipeline input

Open Cryovenom opened this issue 1 year ago • 2 comments

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

Following my Steps to Reproduce results in the following error:

Invoke-DbaDbShrink : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:2 char:23
+ $SimpleDatabases | Invoke-DbaDbShrink -FileType Log -WhatIf
+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ([TEAMMATE]:PSObject) [Invoke-DbaDbShrink], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Invoke-DbaDbShrink

Steps to Reproduce

If I have one or more database objects in a variable, I can't pass it to Invoke-DbaDbShrink on the pipeline.

So for example let's say I grab some databases like this:

$SimpleDatabases = Get-DbaDatabase -SqlInstance "SERVER01\InstanceA" -ExcludeSystem -RecoveryModel Simple

I can do this:

$SimpleDatabases | ForEach-Object { Invoke-DbaDbShrink -SqlInstance $_.SqlInstance -Database $_.Name }

But not this:

$SimpleDatabases | Invoke-DbaDbShrink -FileType Log

Attempting that results in the error I posted in the "What error did you receeive?" box above.

Please confirm that you are running the most recent version of dbatools

2.1.18

Other details or mentions

No response

What PowerShell host was used when producing this error

Windows PowerShell ISE (powershell_ise.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.17763.6189
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.6189
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM-CU26) (KB5035123) - 15.0.4365.2 (X64) Mar 29 2024 23:02:47 Copyright (C) 2019 Microsoft Corporation Enterprise Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> (Build 17763: ) (Hypervisor)

.NET Framework Version

.NET Framework 4.8.4749.0

Cryovenom avatar Oct 10 '24 15:10 Cryovenom

that's not a bug, it's a feature request. This function requires to pass database NAMES along, not Database SMO objects.

niphlod avatar Oct 10 '24 16:10 niphlod

Sorry, I assumed it was already supposed to accept pipeline input and that it wasn't working properly (and thus, a bug) since pretty much all the other DbaTools cmdlets I use that target a database accept a Database object on the pipeline. It didn't occur to me that it would be a Feature Request.

In my script I just had this a line above:

$NotSimpleDatabases | Set-DbaDbRecoveryModel -RecoveryModel Simple -Confirm:$false

So it seemed logical that I could do this:

$SimpleDatabases | Invoke-DbaDbShrink -FileType Log

Cryovenom avatar Oct 10 '24 17:10 Cryovenom