Skip to content

Commit 7edecc8

Browse files
Fix non-Windows Import Errors (#9158)
1 parent 7d2d194 commit 7edecc8

File tree

9 files changed

+24
-163
lines changed

9 files changed

+24
-163
lines changed

private/configurations/configuration.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ if (-not $script:dbatools_ImportFromRegistryDone) {
179179
} else {
180180
Set-DbatoolsConfig -FullName $value.FullName -Value $true -EnableException
181181
}
182-
} else {
182+
} elseif ($null -ne $value.Value) {
183183
Set-DbatoolsConfig -FullName $value.FullName -Value $value.Value -EnableException
184184
}
185185
} else {

private/configurations/settings/tabexpansion.ps1

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@ Set-DbatoolsConfig -FullName 'TabExpansion.Disable' -Value $false -Initialize -V
88

99
# Disable Async TEPP runspace if not needed
1010
if ([Dataplat.Dbatools.TabExpansion.TabExpansionHost]::TeppAsyncDisabled -or [Dataplat.Dbatools.TabExpansion.TabExpansionHost]::TeppDisabled) {
11-
[Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces["dbatools-teppasynccache"].Stop()
11+
$stoptepp = [Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces["dbatools-teppasynccache"]
12+
if ($stoptepp) {
13+
$stoptepp.Stop()
14+
}
1215
} else {
13-
[Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces["dbatools-teppasynccache"].Start()
16+
$starttepp = [Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces["dbatools-teppasynccache"]
17+
if ($starttepp) {
18+
$starttepp.Start()
19+
}
1420
}
1521
} -Description 'Globally disables all TEPP functionality by dbatools'
1622
Set-DbatoolsConfig -FullName 'TabExpansion.Disable.Asynchronous' -Value $false -Initialize -Validation bool -Handler {
1723
[Dataplat.Dbatools.TabExpansion.TabExpansionHost]::TeppAsyncDisabled = $args[0]
1824

1925
# Disable Async TEPP runspace if not needed
2026
if ([Dataplat.Dbatools.TabExpansion.TabExpansionHost]::TeppAsyncDisabled -or [Dataplat.Dbatools.TabExpansion.TabExpansionHost]::TeppDisabled) {
21-
[Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces["dbatools-teppasynccache"].Stop()
27+
$stoptapp = [Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces["dbatools-teppasynccache"]
28+
if ($stoptapp) {
29+
$stoptapp.Stop()
30+
}
2231
} else {
23-
[Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces["dbatools-teppasynccache"].Start()
32+
$starttapp = [Dataplat.Dbatools.Runspace.RunspaceHost]::Runspaces["dbatools-teppasynccache"]
33+
if ($starttapp) {
34+
$starttapp.Start()
35+
}
2436
}
2537
} -Description 'Globally disables asynchronous TEPP updates in the background'
2638
Set-DbatoolsConfig -FullName 'TabExpansion.Disable.Synchronous' -Value $true -Initialize -Validation bool -Handler { [Dataplat.Dbatools.TabExpansion.TabExpansionHost]::TeppSyncDisabled = $args[0] } -Description 'Globally disables synchronous TEPP updates, performed whenever connecting o the server. If this is not disabled, it will only perform updates that are fast to perform, in order to minimize performance impact. This may lead to some TEPP functionality loss if asynchronous updates are disabled.'

private/configurations/settings/userinteraction.ps1

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,10 @@ Set-DbatoolsConfig -Name 'message.minimuminfo' -Value 1 -Initialize -Validation
1111
Set-DbatoolsConfig -Name 'message.minimumverbose' -Value 4 -Initialize -Validation integer0to9 -Handler { [Dataplat.Dbatools.Message.MessageHost]::MinimumVerbose = $args[0] } -Description "The minimum required message level where verbose information is written."
1212
Set-DbatoolsConfig -Name 'message.minimumdebug' -Value 1 -Initialize -Validation integer0to9 -Handler { [Dataplat.Dbatools.Message.MessageHost]::MinimumDebug = $args[0] } -Description "The minimum required message level where debug information is written."
1313

14-
# Default color used by the "Write-Message" function in info mode
15-
Set-DbatoolsConfig -Name 'message.infocolor' -Value 'Cyan' -Initialize -Validation consolecolor -Handler { [Dataplat.Dbatools.Message.MessageHost]::InfoColor = $args[0] } -Description "The color to use when writing text to the screen on PowerShell."
16-
Set-DbatoolsConfig -Name 'message.developercolor' -Value 'Grey' -Initialize -Validation consolecolor -Handler { [Dataplat.Dbatools.Message.MessageHost]::DeveloperColor = $args[0] } -Description "The color to use when writing text with developer specific additional information to the screen on PowerShell."
17-
Set-DbatoolsConfig -Name 'message.info.color.emphasis' -Value 'green' -Initialize -Validation "consolecolor" -Handler { [Dataplat.Dbatools.Message.MessageHost]::InfoColorEmphasis = $args[0] } -Description "The color to use when emphasizing written text to the screen on PowerShell."
18-
Set-DbatoolsConfig -Name 'message.info.color.subtle' -Value 'gray' -Initialize -Validation "consolecolor" -Handler { [Dataplat.Dbatools.Message.MessageHost]::InfoColorSubtle = $args[0] } -Description "The color to use when making writing text to the screen on PowerShell appear subtle."
1914
Set-DbatoolsConfig -Name 'message.consoleoutput.disable' -Value $false -Initialize -Validation "bool" -Handler { [Dataplat.Dbatools.Message.MessageHost]::DisableVerbosity = $args[0] } -Description "Global toggle that allows disabling all regular messages to screen. Messages from '-Verbose' and '-Debug' are unaffected"
2015
Set-DbatoolsConfig -Name 'message.transform.errorqueuesize' -Value 512 -Initialize -Validation "integerpositive" -Handler { [Dataplat.Dbatools.Message.MessageHost]::TransformErrorQueueSize = $args[0] } -Description "The size of the queue for transformation errors. May be useful for advanced development, but can be ignored usually."
2116
Set-DbatoolsConfig -Name 'message.nestedlevel.decrement' -Value 0 -Initialize -Validation "integer0to9" -Handler { [Dataplat.Dbatools.Message.MessageHost]::NestedLevelDecrement = $args[0] } -Description "How many levels should be reduced per callstack depth. This makes commands less verbose, the more nested they are called"
2217

23-
# Messaging mode in non-critical terminations
24-
Set-DbatoolsConfig -Name 'message.mode.default' -Value ([DbaMode]::Strict) -Initialize -Validation string -Handler { } -Description "The mode controls how some functions handle non-critical terminations by default. Strict: Write a warning | Lazy: Write a message | Report: Generate a report object"
25-
Set-DbatoolsConfig -Name 'message.mode.lazymessagelevel' -Value 4 -Initialize -Validation integer0to9 -Handler { } -Description "At what level will the lazy message be written? (By default invisible to the user)"
26-
27-
# Enable Developer mode
28-
Set-DbatoolsConfig -Name 'developer.mode.enable' -Value $false -Initialize -Validation bool -Handler { [Dataplat.Dbatools.Message.MessageHost]::DeveloperMode = $args[0] } -Description "Developermode enables advanced logging and verbosity features. There is little benefit for enabling this as a regular user. but developers can use it to more easily troubleshoot issues."
29-
3018
# Message display style options
3119
Set-DbatoolsConfig -Name 'message.style.breadcrumbs' -Value $false -Initialize -Validation "bool" -Handler { [Dataplat.Dbatools.Message.MessageHost]::EnableMessageBreadcrumbs = $args[0] } -Description "Controls how messages are displayed. Enables Breadcrumb display, showing the entire callstack. Takes precedence over command name display."
3220
Set-DbatoolsConfig -Name 'message.style.functionname' -Value $true -Initialize -Validation "bool" -Handler { [Dataplat.Dbatools.Message.MessageHost]::EnableMessageDisplayCommand = $args[0] } -Description "Controls how messages are displayed. Enables command name, showing the name of the writing command. Is overwritten by enabling breadcrumbs."

private/configurations/validation/consolecolor.ps1

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,4 @@
11
function Write-HostColor {
2-
<#
3-
.SYNOPSIS
4-
Function that recognizes html-style tags to insert color into printed text.
5-
6-
.DESCRIPTION
7-
Function that recognizes html-style tags to insert color into printed text.
8-
9-
Color tags should be designed to look like this:
10-
<c="<console color>">Text</c>
11-
For example this would be a valid string:
12-
"This message should <c="red">partially be painted in red</c>."
13-
14-
This allows specifying color within strings and avoids having to piece together colored text in multiple calls to Write-Host.
15-
Only colors that are part of the ConsoleColor enumeration can be used. Bad colors will be ignored in favor of the default color.
16-
17-
.PARAMETER String
18-
The message to write to host.
19-
20-
.PARAMETER DefaultColor
21-
Default: (Get-DbatoolsConfigValue -Name "message.infocolor")
22-
The color to write stuff to host in when no (or bad) color-code was specified.
23-
24-
.EXAMPLE
25-
Write-HostColor -String 'This is going to be <c="red">bloody red</c> text! And this is <c="green">green stuff</c> for extra color'
26-
27-
Will print the specified line in multiple colors
28-
29-
.EXAMPLE
30-
$string1 = 'This is going to be <c="red">bloody red</c> text! And this is <c="green">green stuff</c> for extra color'
31-
$string2 = '<c="red">bloody red</c> text! And this is <c="green">green stuff</c> for extra color'
32-
$string3 = 'This is going to be <c="red">bloody red</c> text! And this is <c="green">green stuff</c>'
33-
$string1, $string2, $string3 | Write-HostColor -DefaultColor "Magenta"
34-
35-
Will print all three lines, respecting the color-codes, but use the color "Magenta" as default color.
36-
37-
.EXAMPLE
38-
$stringLong = @"
39-
Dear <c="red">Sirs</c><c="green"> and</c> <c="blue">Madams</c>,
40-
41-
it has come to our attention that you are not sufficiently <c="darkblue">awesome!</c>
42-
Kindly improve your <c="yellow">AP</c> (<c="magenta">awesome-ness points</c>) by at least 50% to maintain you membership in Awesome Inc!
43-
44-
You have <c="green">27 3/4</c> days time to meet this deadline. <c="darkyellow">After this we will unfortunately be forced to rend you assunder and sacrifice your remains to the devil</c>.
45-
46-
Best regards,
47-
<c="red">Luzifer</c>
48-
"@
49-
Write-HostColor -String $stringLong
50-
51-
Will print a long multiline text in its entirety while still respecting the colorcodes
52-
#>
53-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
54-
[CmdletBinding()]
55-
param (
56-
[Parameter(ValueFromPipeline)]
57-
[string[]]
58-
$String,
59-
60-
[ConsoleColor]
61-
$DefaultColor = (Get-DbatoolsConfigValue -Name "message.infocolor")
62-
)
63-
process {
64-
foreach ($line in $String) {
65-
foreach ($row in $line.Split("`n").Split([environment]::NewLine)) {
66-
if ($row -notlike '*<c=["'']*["'']>*</c>*') { Write-Host -Object $row -ForegroundColor $DefaultColor }
67-
else {
68-
$match = ($row | Select-String '<c=["''](.*?)["'']>(.*?)</c>' -AllMatches).Matches
69-
$index = 0
70-
$count = 0
71-
72-
while ($count -le $match.Count) {
73-
if ($count -lt $Match.Count) {
74-
Write-Host -Object $match[$count].Groups[2].Value -ForegroundColor $DefaultColor -NoNewline -ErrorAction Stop
75-
$index = $match[$count].Index + $match[$count].Length
76-
$count++
77-
} else {
78-
Write-Host -Object $row.SubString($index) -ForegroundColor $DefaultColor
79-
$count++
80-
}
81-
}
82-
}
83-
}
84-
}
85-
}
2+
param ()
3+
process {}
864
}

public/Remove-DbaAgentJob.ps1

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ function Remove-DbaAgentJob {
2626
Specifies to keep the schedules attached to this job if they are not attached to any other job.
2727
By default the unused schedule is deleted.
2828
29-
.PARAMETER Mode
30-
Default: Strict
31-
How strict does the command take lesser issues?
32-
Strict: Interrupt if the job specified doesn't exist.
33-
Lazy: Silently skip over jobs that don't exist.
34-
3529
.PARAMETER InputObject
3630
Accepts piped input from Get-DbaAgentJob
3731
@@ -85,7 +79,6 @@ function Remove-DbaAgentJob {
8579
[object[]]$Job,
8680
[switch]$KeepHistory,
8781
[switch]$KeepUnusedSchedule,
88-
[DbaMode]$Mode = (Get-DbatoolsConfigValue -FullName 'message.mode.default' -Fallback "Strict"),
8982
[parameter(ValueFromPipeline)]
9083
[Microsoft.SqlServer.Management.Smo.Agent.Job[]]$InputObject,
9184
[switch]$EnableException
@@ -100,14 +93,7 @@ function Remove-DbaAgentJob {
10093

10194
foreach ($j in $Job) {
10295
if ($Server.JobServer.Jobs.Name -notcontains $j) {
103-
switch ($Mode) {
104-
'Lazy' {
105-
Write-Message -Level Verbose -Message "Job $j doesn't exists on $instance." -Target $instance
106-
}
107-
'Strict' {
108-
Stop-Function -Message "Job $j doesn't exist on $instance." -Continue -ContinueLabel main -Target $instance -Category InvalidData
109-
}
110-
}
96+
Stop-Function -Message "Job $j doesn't exist on $instance." -Continue -ContinueLabel main -Target $instance -Category InvalidData
11197
}
11298
$InputObject += ($Server.JobServer.Jobs | Where-Object Name -eq $j)
11399
}

public/Remove-DbaAgentJobStep.ps1

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ function Remove-DbaAgentJobStep {
2222
.PARAMETER StepName
2323
The name of the job step.
2424
25-
.PARAMETER Mode
26-
Default: Strict
27-
How strict does the command take lesser issues?
28-
Strict: Interrupt if the configuration already has the same value as the one specified.
29-
Lazy: Silently skip over instances that already have this configuration at the specified value.
30-
3125
.PARAMETER WhatIf
3226
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
3327
@@ -82,7 +76,6 @@ function Remove-DbaAgentJobStep {
8276
[Parameter(Mandatory)]
8377
[ValidateNotNullOrEmpty()]
8478
[string]$StepName,
85-
[DbaMode]$Mode = (Get-DbatoolsConfigValue -Name 'message.mode.default' -Fallback "Strict"),
8679
[switch]$EnableException
8780
)
8881

@@ -99,25 +92,11 @@ function Remove-DbaAgentJobStep {
9992
Write-Message -Level Verbose -Message "Processing job $j"
10093
# Check if the job exists
10194
if ($Server.JobServer.Jobs.Name -notcontains $j) {
102-
switch ($Mode) {
103-
'Lazy' {
104-
Write-Message -Level Verbose -Message "Job $j doesn't exists on $instance." -Target $instance
105-
}
106-
'Strict' {
107-
Stop-Function -Message "Job $j doesnn't exist on $instance." -Continue -ContinueLabel main -Target $instance -Category InvalidData
108-
}
109-
}
95+
Stop-Function -Message "Job $j doesnn't exist on $instance." -Continue -ContinueLabel main -Target $instance -Category InvalidData
11096
} else {
11197
# Check if the job step exists
11298
if ($Server.JobServer.Jobs[$j].JobSteps.Name -notcontains $StepName) {
113-
switch ($Mode) {
114-
'Lazy' {
115-
Write-Message -Level Verbose -Message "Step $StepName doesn't exist for $job on $instance." -Target $instance
116-
}
117-
'Strict' {
118-
Stop-Function -Message "Step $StepName doesn't exist for $job on $instance." -Continue -ContinueLabel main -Target $instance -Category InvalidData
119-
}
120-
}
99+
Stop-Function -Message "Step $StepName doesn't exist for $job on $instance." -Continue -ContinueLabel main -Target $instance -Category InvalidData
121100
} else {
122101
# Execute
123102
if ($PSCmdlet.ShouldProcess($instance, "Removing the job step $StepName for job $j")) {

tests/Remove-DbaAgentJob.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
55
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
66
Context "Validate parameters" {
77
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
8-
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Job', 'KeepHistory', 'KeepUnusedSchedule', 'Mode', 'InputObject', 'EnableException'
8+
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Job', 'KeepHistory', 'KeepUnusedSchedule', 'InputObject', 'EnableException'
99
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
1010
It "Should only contain our specific parameters" {
1111
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0

tests/Remove-DbaAgentJobStep.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
55
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
66
Context "Validate parameters" {
77
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
8-
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Job', 'StepName', 'Mode', 'EnableException'
8+
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Job', 'StepName', 'EnableException'
99
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
1010
It "Should only contain our specific parameters" {
1111
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0

0 commit comments

Comments
 (0)