dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Do not treat a null value passed to the "-Job" parameter as a request for ALL jobs

Open dsantunes opened this issue 6 months ago • 0 comments

Summarize Functionality

Passing null values to parameters will result in errors instead of the cmdlets proceeding as if the parameter was not explicitly passed.

Is there a command that is similiar or close to what you are looking for?

Yes

Technical Details

Not sure whether to report this as a bug or feature request, but here it goes.

I've just had a fun incident where I deleted all SQL jobs on an instance because I passed a variable name which didn't exist:

$sqlServer = "SqlServer"
$rightVariable = "This is my SQL job name"

$sqlJob = Get-DbaAgentJob -SqlInstance $sqlServer -Job $wrongVariable

Remove-DbaAgentJob -SqlInstance $sqlServer -Job $sqlJob -Confirm:$false

In the above example, $wrongVariable doesn't exist, and $sqlJob ends up with ALL SQL JOBS in it, which are then deleted. (Confirmation was skipped because this is meant to run without human interaction.)

The same happens if I run the command like this:

$sqlJob = Get-DbaAgentJob -SqlInstance $sqlServer -Job "" $sqlJob = Get-DbaAgentJob -SqlInstance $sqlServer -Job $null

I would expect the cmdlet to NOT proceed if there is a null value passed to a parameter. The parameter is not MANDATORY, but if it's being explicitly passed, then it should contain something.

I don't know how much of this is Powershell's default behaviour VS a conscious design decision on the dbatools Cmdlets.

dsantunes avatar Aug 06 '24 13:08 dsantunes