Skip to content

Commit

Permalink
Merge pull request dataplat#4831 from sqlcollaborative/development
Browse files Browse the repository at this point in the history
0.9.720
  • Loading branch information
potatoqualitee authored Dec 16, 2018
2 parents 7a85041 + 7a58d00 commit 5b4b739
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 20 deletions.
Binary file modified allcommands.zip
Binary file not shown.
12 changes: 10 additions & 2 deletions bin/dbatools-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -22177,6 +22177,14 @@
"false",
"0"
],
[
"ExactLength",
"Mask string values to the same length. So \u0027Tate\u0027 will be replaced with 4 random characters.",
"",
false,
"false",
"False"
],
[
"EnableException",
"By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.\r\nThis avoids overwhelming you with \"sea of red\" exceptions, but is inconvenient because it basically disables advanced scripting.\r\nUsing this switch turns this \"nice by default\" feature off and enables you to catch exceptions with your own try/catch.",
Expand All @@ -22202,7 +22210,7 @@
""
]
],
"Syntax": "Invoke-DbaDbDataMasking [[-SqlInstance] \u003cDbaInstanceParameter[]\u003e] [[-SqlCredential] \u003cPSCredential\u003e] [[-Database] \u003cString[]\u003e] [-FilePath] \u003cObject\u003e [[-Locale] \u003cString\u003e] [[-CharacterString] \u003cString\u003e] [[-Table] \u003cString[]\u003e] [[-Column] \u003cString[]\u003e] [[-ExcludeTable] \u003cString[]\u003e] [[-ExcludeColumn] \u003cString[]\u003e] [[-Query] \u003cString\u003e] [[-MaxValue] \u003cInt32\u003e] [-EnableException] [-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]"
"Syntax": "Invoke-DbaDbDataMasking [[-SqlInstance] \u003cDbaInstanceParameter[]\u003e] [[-SqlCredential] \u003cPSCredential\u003e] [[-Database] \u003cString[]\u003e] [-FilePath] \u003cObject\u003e [[-Locale] \u003cString\u003e] [[-CharacterString] \u003cString\u003e] [[-Table] \u003cString[]\u003e] [[-Column] \u003cString[]\u003e] [[-ExcludeTable] \u003cString[]\u003e] [[-ExcludeColumn] \u003cString[]\u003e] [[-Query] \u003cString\u003e] [[-MaxValue] \u003cInt32\u003e] [-ExactLength] [-EnableException] [-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]"
},
{
"Name": "Invoke-DbaDbDecryptObject",
Expand Down Expand Up @@ -37271,7 +37279,7 @@
"CommandName": "Set-DbaSpn",
"Availability": "Windows only",
"Links": "https://dbatools.io/Set-DbaSpn",
"Examples": "-------------------------- EXAMPLE 1 --------------------------\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account\nPS C:\\\u003e Set-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account -EnableException\nConnects to Active Directory and adds a provided SPN to the given account.\r\nConnects to Active Directory and adds a provided SPN to the given account, suppressing all error messages and throw exceptions that can be caught instead\n-------------------------- EXAMPLE 2 --------------------------\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account -Credential ad\\sqldba\nConnects to Active Directory and adds a provided SPN to the given account. Uses alternative account to connect to AD.\n-------------------------- EXAMPLE 3 --------------------------\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc\\SQLSERVERA.domain.something -ServiceAccount domain\\account -NoDelegation\nConnects to Active Directory and adds a provided SPN to the given account, without the delegation.\n-------------------------- EXAMPLE 4 --------------------------\nPS C:\\\u003eTest-DbaSpn -ComputerName sql2016 | Where { $_.isSet -eq $false } | Set-DbaSpn\nSets all missing SPNs for sql2016\n-------------------------- EXAMPLE 5 --------------------------\nPS C:\\\u003eTest-DbaSpn -ComputerName sql2016 | Where { $_.isSet -eq $false } | Set-DbaSpn -WhatIf\nDisplays what would happen trying to set all missing SPNs for sql2016",
"Examples": "-------------------------- EXAMPLE 1 --------------------------\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\\account\nPS C:\\\u003e Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\\account -EnableException\nConnects to Active Directory and adds a provided SPN to the given account.\r\nConnects to Active Directory and adds a provided SPN to the given account, suppressing all error messages and throw exceptions that can be caught instead\n-------------------------- EXAMPLE 2 --------------------------\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\\account -Credential ad\\sqldba\nConnects to Active Directory and adds a provided SPN to the given account. Uses alternative account to connect to AD.\n-------------------------- EXAMPLE 3 --------------------------\nPS C:\\\u003eSet-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\\account -NoDelegation\nConnects to Active Directory and adds a provided SPN to the given account, without the delegation.\n-------------------------- EXAMPLE 4 --------------------------\nPS C:\\\u003eTest-DbaSpn -ComputerName sql2016 | Where { $_.isSet -eq $false } | Set-DbaSpn\nSets all missing SPNs for sql2016\n-------------------------- EXAMPLE 5 --------------------------\nPS C:\\\u003eTest-DbaSpn -ComputerName sql2016 | Where { $_.isSet -eq $false } | Set-DbaSpn -WhatIf\nDisplays what would happen trying to set all missing SPNs for sql2016",
"Params": [
[
"SPN",
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.720] - 2018-12-16
### Fixed
* Enhanced outputs of Invoke-DbaDbDataMasking
* Save-DbaDiagnosticQuery to work with lightly malformed links

## [0.9.719] - 2018-12-15
### Added
* Piping to Get-DbaDbSpace
Expand Down
2 changes: 1 addition & 1 deletion dbatools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '0.9.719'
ModuleVersion = '0.9.720'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
Expand Down
35 changes: 28 additions & 7 deletions functions/Invoke-DbaDbDataMasking.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function Invoke-DbaDbDataMasking {
Useful for adhoc updates and testing, otherwise, the config file should be used.
.PARAMETER ExactLength
Mask string values to the same length. So 'Tate' will be replaced with 4 random characters.
.PARAMETER Force
Forcefully execute commands when needed
Expand Down Expand Up @@ -117,6 +120,7 @@ function Invoke-DbaDbDataMasking {
[string[]]$ExcludeColumn,
[string]$Query,
[int]$MaxValue,
[switch]$ExactLength,
[switch]$EnableException
)
begin {
Expand Down Expand Up @@ -147,12 +151,11 @@ function Invoke-DbaDbDataMasking {
return
}
}

if ($Table) {
$tables = $tables | Where-Object Name -in $Table
}


foreach ($tabletest in $tables.Tables) {
if ($Table -and $tabletest.Name -notin $Table) {
continue
}
foreach ($columntest in $tabletest.Columns) {
if ($columntest.ColumnType -in 'hierarchyid', 'geography', 'xml' -and $columntest.Name -notin $Column) {
Stop-Function -Message "$($columntest.ColumnType) is not supported, please remove the column $($columntest.Name) from the $($tabletest.Name) table" -Target $tables
Expand All @@ -174,7 +177,7 @@ function Invoke-DbaDbDataMasking {
foreach ($db in (Get-DbaDatabase -SqlInstance $server -Database $Database)) {
$stepcounter = 0
foreach ($tableobject in $tables.Tables) {
if ($tableobject.Name -in $ExcludeTable) {
if ($tableobject.Name -in $ExcludeTable -or ($Table -and $tableobject.Name -notin $Table)) {
Write-Message -Level Verbose -Message "Skipping $($tableobject.Name) because it is explicitly excluded"
continue
}
Expand All @@ -189,9 +192,10 @@ function Invoke-DbaDbDataMasking {

$data = $db.Query($query) | ConvertTo-DbaDataTable
} catch {
Stop-Function -Message "Something went wrong retrieving the data from table $($tableobject.Name)" -Target $Database
Stop-Function -Message "Failure retrieving the data from table $($tableobject.Name)" -Target $Database -ErrorRecord $_ -Continue
}

$elapsed = [System.Diagnostics.Stopwatch]::StartNew()
$tablecolumns = $tableobject.Columns

if ($Column) {
Expand Down Expand Up @@ -297,6 +301,13 @@ function Invoke-DbaDbDataMasking {
'uniqueidentifier' {
$faker.System.Random.Guid().Guid
}
'userdefineddatatype' {
if ($columnobject.MaxValue -eq 1) {
$faker.System.Random.Bool()
} else {
$null
}
}
default {
$null
}
Expand Down Expand Up @@ -335,6 +346,11 @@ function Invoke-DbaDbDataMasking {
if ($max -eq -1) {
$max = 1024
}

if ($columnobject.SubType -eq "String" -and (Test-Bound -ParameterName ExactLength)) {
$max = ($row.$($columnobject.Name)).Length
}

if ($columnobject.ColumnType -eq 'xml') {
$null
} else {
Expand All @@ -345,6 +361,9 @@ function Invoke-DbaDbDataMasking {
if ($max -eq -1) {
$max = 1024
}
if ((Test-Bound -ParameterName ExactLength)) {
$max = ($row.$($columnobject.Name)).ToString().Length
}
$faker.Random.String2($max, $charstring)
}
}
Expand Down Expand Up @@ -387,6 +406,8 @@ function Invoke-DbaDbDataMasking {
Schema = $tableobject.Schema
Table = $tableobject.Name
Columns = $tableobject.Columns.Name
Rows = $($data.Rows.Count)
Elapsed = [prettytimespan]$elapsed.Elapsed
Status = "Masked"
}
}
Expand Down
17 changes: 17 additions & 0 deletions functions/New-DbaDbMaskingConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,23 @@ function New-DbaDbMaskingConfig {
$subType = "Number"
$MaxValue = 255
}
"varbinary" {
$subType = "Byte"
$MaxValue = $columnLength
}
"varbinary" {
$subType = "Byte"
$MaxValue = $columnLength
}
"userdefineddatatype" {
if ($columnLength -eq 1) {
$subType = "Bool"
$MaxValue = $columnLength
} else {
$subType = "String"
$MaxValue = $columnLength
}
}
default {
$subType = "String"
$MaxValue = $columnLength
Expand Down
11 changes: 7 additions & 4 deletions functions/Save-DbaDiagnosticQueryScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Save-DbaDiagnosticQueryScript {
$glenberryrss = "http://www.sqlskills.com/blogs/glenn/feed/"
$glenberrysql = @()

Write-Message -Level Output -Message "Downloading RSS Feed"
Write-Message -Level Verbose -Message "Downloading RSS Feed"
$rss = [xml](get-webdata -uri $glenberryrss)
$Feed = $rss.rss.Channel

Expand All @@ -90,12 +90,15 @@ function Save-DbaDiagnosticQueryScript {
break
}
}
Write-Message -Level Output -Message "Found $($glenberrysql.Count) documents to download"
Write-Message -Level Verbose -Message "Found $($glenberrysql.Count) documents to download"
foreach ($doc in $glenberrysql) {
try {
Write-Message -Level Output -Message "Downloading $($doc.URL)"
$link = $doc.URL.ToString().Replace('dl=0', 'dl=1')
Write-Message -Level Verbose -Message "Downloading $link)"
Write-ProgressHelper -Activity "Downloading Glenn Berry's most recent DMVs" -ExcludePercent -Message "Downloading $link" -StepNumber 1
$filename = "{0}\SQLServerDiagnosticQueries_{1}_{2}.sql" -f $Path, $doc.SQLVersion, "$($doc.FileYear)$($doc.FileMonth)"
Invoke-TlsWebRequest -Uri $doc.URL.ToString().Replace('dl\=0','dl\=1') -OutFile $filename -ErrorAction Stop
Invoke-TlsWebRequest -Uri $link -OutFile $filename -ErrorAction Stop
Get-ChildItem -Path $filename
} catch {
Stop-Function -Message "Requesting and writing file failed: $_" -Target $filename -ErrorRecord $_
return
Expand Down
8 changes: 4 additions & 4 deletions functions/Set-DbaSpn.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ function Set-DbaSpn {
https://dbatools.io/Set-DbaSpn
.EXAMPLE
PS C:\> Set-DbaSpn -SPN MSSQLSvc\SQLSERVERA.domain.something -ServiceAccount domain\account
PS C:\> Set-DbaSpn -SPN MSSQLSvc\SQLSERVERA.domain.something -ServiceAccount domain\account -EnableException
PS C:\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\account
PS C:\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\account -EnableException
Connects to Active Directory and adds a provided SPN to the given account.
Connects to Active Directory and adds a provided SPN to the given account, suppressing all error messages and throw exceptions that can be caught instead
.EXAMPLE
PS C:\> Set-DbaSpn -SPN MSSQLSvc\SQLSERVERA.domain.something -ServiceAccount domain\account -Credential ad\sqldba
PS C:\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\account -Credential ad\sqldba
Connects to Active Directory and adds a provided SPN to the given account. Uses alternative account to connect to AD.
.EXAMPLE
PS C:\> Set-DbaSpn -SPN MSSQLSvc\SQLSERVERA.domain.something -ServiceAccount domain\account -NoDelegation
PS C:\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\account -NoDelegation
Connects to Active Directory and adds a provided SPN to the given account, without the delegation.
Expand Down
2 changes: 1 addition & 1 deletion tests/Invoke-DbaDbDataMasking.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Invoke-DbaDbDataMasking).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'FilePath', 'Locale', 'CharacterString', 'Table', 'Column', 'ExcludeTable', 'ExcludeColumn', 'Query', 'MaxValue', 'EnableException'
$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'FilePath', 'Locale', 'CharacterString', 'Table', 'Column', 'ExcludeTable', 'ExcludeColumn', 'Query', 'MaxValue', 'EnableException','ExactLength'
It "Should contain our specific parameters" {
( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $knownParameters.Count
}
Expand Down
3 changes: 2 additions & 1 deletion tests/pester.groups.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ $TestsRunGroups = @{
'Test-DbaDbVirtualLogFile',
'Test-DbaAgentJobOwner',
'Resume-DbaAgDbDataMovement',
'Get-DbaDbMasterKey'
'Get-DbaDbMasterKey',
'Test-DbaJobOwner'
)
# do not run everywhere
"disabled" = @()
Expand Down

0 comments on commit 5b4b739

Please sign in to comment.