Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dsantunes opened this issue Aug 6, 2024 · 0 comments
Labels
feature triage required New issue that has not been reviewed by maintainers

Comments

@dsantunes
Copy link

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 dsantunes added feature triage required New issue that has not been reviewed by maintainers labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature triage required New issue that has not been reviewed by maintainers
Projects
None yet
Development

No branches or pull requests

1 participant