Skip to content

Commit

Permalink
0.9.826
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed May 13, 2019
1 parent f6cae60 commit 1a713ee
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 35 deletions.
97 changes: 63 additions & 34 deletions allcommands.ps1
Expand Up @@ -11642,6 +11642,9 @@ function Copy-DbaLogin {
)

begin {
if ($SyncOnly) {
Write-Message -Level Warning -Message "Please note that SyncOnly will be removed in dbatools 1.0. Please use Sync-DbaLoginPermission instead."
}
function Copy-Login {
foreach ($sourceLogin in $sourceServer.Logins) {
$userName = $sourceLogin.name
Expand Down Expand Up @@ -13572,7 +13575,7 @@ function Copy-DbaSsisCatalog {
Tags: Migration, SSIS
Author: Phil Schwartz (philschwartz.me, @pschwartzzz)

dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -22778,11 +22781,13 @@ function Find-DbaInstance {

process {
foreach ($computer in $Target) {
$stepCounter = 0
if ($computersScanned.Contains($computer.ComputerName)) {
continue
} else {
$null = $computersScanned.Add($computer.ComputerName)
}
Write-ProgressHelper -Activity "Processing: $($computer)" -StepNumber ($stepCounter++) -Message "Starting"
Write-Message -Level Verbose -Message "Processing: $($computer)" -Target $computer -FunctionName Find-DbaInstance

#region Null variables to prevent scope lookup on conditional existence
Expand All @@ -22799,17 +22804,21 @@ function Find-DbaInstance {

#region Gather data
if ($ScanType -band [Sqlcollaborative.Dbatools.Discovery.DbaInstanceScanType]::DNSResolve) {
try { $resolution = [System.Net.Dns]::GetHostEntry($computer.ComputerName) }
catch {
try {
Write-ProgressHelper -Activity "Processing: $($computer)" -StepNumber ($stepCounter++) -Message "Performing DNS resolution"
$resolution = [System.Net.Dns]::GetHostEntry($computer.ComputerName)
} catch {
# here to avoid an empty catch
$null = 1
}
}

if ($ScanType -band [Sqlcollaborative.Dbatools.Discovery.DbaInstanceScanType]::Ping) {
$ping = New-Object System.Net.NetworkInformation.Ping
try { $pingReply = $ping.Send($computer.ComputerName) }
catch {
try {
Write-ProgressHelper -Activity "Processing: $($computer)" -StepNumber ($stepCounter++) -Message "Waiting for ping response"
$pingReply = $ping.Send($computer.ComputerName)
} catch {
# here to avoid an empty catch
$null = 1
}
Expand All @@ -22819,19 +22828,23 @@ function Find-DbaInstance {
$computerByName = $computer.ComputerName
if ($resolution.HostName) { $computerByName = $resolution.HostName }
if ($computerByName -notmatch "$([dbargx]::IPv4)|$([dbargx]::IPv6)") {
try { $sPNs = Get-DomainSPN -DomainController $DomainController -Credential $Credential -ComputerName $computerByName -GetSPN }
catch {
try {
Write-ProgressHelper -Activity "Processing: $($computer)" -StepNumber ($stepCounter++) -Message "Finding SPNs"
$sPNs = Get-DomainSPN -DomainController $DomainController -Credential $Credential -ComputerName $computerByName -GetSPN
} catch {
# here to avoid an empty catch
$null = 1
}
}
}

# $ports required for all scans
Write-ProgressHelper -Activity "Processing: $($computer)" -StepNumber ($stepCounter++) -Message "Testing TCP ports"
$ports = $TCPPort | Test-TcpPort -ComputerName $computer

if ($ScanType -band [Sqlcollaborative.Dbatools.Discovery.DbaInstanceScanType]::Browser) {
try {
Write-ProgressHelper -Activity "Processing: $($computer)" -StepNumber ($stepCounter++) -Message "Probing Browser service"
$browseResult = Get-SQLInstanceBrowserUDP -ComputerName $computer -EnableException
} catch {
# here to avoid an empty catch
Expand All @@ -22840,8 +22853,12 @@ function Find-DbaInstance {
}

if ($ScanType -band [Sqlcollaborative.Dbatools.Discovery.DbaInstanceScanType]::SqlService) {
if ($Credential) { $services = Get-DbaService -ComputerName $computer -Credential $Credential -EnableException -ErrorAction Ignore -WarningAction SilentlyCOntinue }
else { $services = Get-DbaService -ComputerName $computer -ErrorAction Ignore -WarningAction SilentlyContinue }
Write-ProgressHelper -Activity "Processing: $($computer)" -StepNumber ($stepCounter++) -Message "Finding SQL services using SQL WMI"
if ($Credential) {
$services = Get-DbaService -ComputerName $computer -Credential $Credential -EnableException -ErrorAction Ignore -WarningAction SilentlyCOntinue
} else {
$services = Get-DbaService -ComputerName $computer -ErrorAction Ignore -WarningAction SilentlyContinue
}
}
#endregion Gather data

Expand Down Expand Up @@ -48934,7 +48951,7 @@ function Get-DbaServerAuditSpecification {
Tags: Audit, Security, SqlAudit
Author: Garry Bargsley (@gbargsley), http://blog.garrybargsley.com

dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -82492,7 +82509,7 @@ function Remove-DbaDbMirror {
.NOTES
Tags: Mirror, HA
Author: Chrissy LeMaire (@cl), netnerds.net
dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -90649,7 +90666,7 @@ function Set-DbaAgentSchedule {

if ($EndTime) {
Write-Message -Message "Setting job schedule end time to $EndTime for schedule $ScheduleName" -Level Verbose
$JobSchedule.ActiveStartTimeOfDay = $EndTime
$JobSchedule.ActiveEndTimeOfDay = $EndTime
}
#endregion job step options

Expand Down Expand Up @@ -99620,7 +99637,7 @@ function Sync-DbaLoginPermission {
$username = $sourceLogin.Name
$currentLogin = $sourceServer.ConnectionContext.TrueLogin

Write-ProgressHelper -Activity "Executing Sync-DbaLoginPermission" -StepNumber ($stepCounter++) -Message "Updating permissions for $username on $($destServer.Name)" -TotalSteps $alllogins.count
Write-ProgressHelper -Activity "Executing Sync-DbaLoginPermission to sync login permissions from $($sourceServer.Name)" -StepNumber ($stepCounter++) -Message "Updating permissions for $username on $($destServer.Name)" -TotalSteps $alllogins.count

if ($currentLogin -eq $username) {
Write-Message -Level Verbose -Message "Sync does not modify the permissions of the current user. Skipping."
Expand Down Expand Up @@ -100069,7 +100086,7 @@ function Test-DbaBuild {
Tags: SqlBuild, Version
Author: Simone Bizzotto (@niphold) | Friedrich Weinmann (@FredWeinmann)

dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -112165,7 +112182,7 @@ function Convert-ByteToHexString {
.NOTES
Tags: Login, Internal
Author: Kirill Kravtsov (@nvarscar)
dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -112349,7 +112366,7 @@ function Convert-HexStringToByte {
.NOTES
Tags: Login, Internal
Author: Kirill Kravtsov (@nvarscar)
dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -112584,7 +112601,7 @@ function Get-BackupAncientHistory {
.NOTES
Author: Stuart Moore (@napalmgram), stuart-moore.com

dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -112815,7 +112832,7 @@ function Get-DbaADObject {
.NOTES
Author: Niphlod, https://github.com/niphlod
Tags:
dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -112985,7 +113002,7 @@ function Get-DbaDbPhysicalFile {
.NOTES
Author: Simone Bizzotto

dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
#>
Expand Down Expand Up @@ -114159,7 +114176,7 @@ function Get-PasswordHash {
.NOTES
Tags: Login, Internal
Author: Kirill Kravtsov (@nvarscar)
dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -116869,7 +116886,7 @@ function Invoke-DbMirrorValidation {
.NOTES
Tags: Mirror, HA
Author: Chrissy LeMaire (@cl), netnerds.net
dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
.EXAMPLE
Expand Down Expand Up @@ -119014,7 +119031,7 @@ function Test-DbaLsnChain {
.NOTES
Author: Stuart Moore (@napalmgram), stuart-moore.com
Tags:
dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -119145,7 +119162,7 @@ function Test-DbaRestoreVersion {
.NOTES
Author: Stuart Moore (@napalmgram), stuart-moore.com
Tags:
dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com)
dbatools PowerShell module (https://dbatools.io)
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -119844,7 +119861,12 @@ function Update-SqlPermission {
$source = $SourceServer.DomainInstanceName
$userName = $SourceLogin.Name

$SourceServer.ConnectionContext.Disconnect()
$saname = Get-SaLoginName -SqlInstance $DestServer

# gotta close because enum repeatedly causes problems with the datareader
$null = $SourceServer.ConnectionContext.SqlConnectionObject.Close()
$null = $DestServer.ConnectionContext.SqlConnectionObject.Close()

# Server Roles: sysadmin, bulklogin, etc
foreach ($role in $SourceServer.Roles) {
$roleName = $role.Name
Expand All @@ -119867,11 +119889,13 @@ function Update-SqlPermission {
if ($roleMembers -contains $userName) {
if ($null -ne $destRole) {
if ($Pscmdlet.ShouldProcess($destination, "Adding $userName to $roleName server role.")) {
try {
$destRole.AddMember($userName)
Write-Message -Level Verbose -Message "Adding $userName to $roleName server role on $destination successfully performed."
} catch {
Stop-Function -Message "Failed to add $userName to $roleName server role on $destination." -Target $role -ErrorRecord $_
if ($userName -ne $saname) {
try {
$destRole.AddMember($userName)
Write-Message -Level Verbose -Message "Adding $userName to $roleName server role on $destination successfully performed."
} catch {
Stop-Function -Message "Failed to add $userName to $roleName server role on $destination." -Target $role -ErrorRecord $_
}
}
}
}
Expand Down Expand Up @@ -119912,6 +119936,9 @@ function Update-SqlPermission {
Securables: Connect SQL, View any database, Administer Bulk Operations, etc.
#>

$null = $sourceServer.ConnectionContext.SqlConnectionObject.Close()
$null = $destServer.ConnectionContext.SqlConnectionObject.Close()

$perms = $SourceServer.EnumServerPermissions($userName)
foreach ($perm in $perms) {
$permState = $perm.PermissionState
Expand Down Expand Up @@ -120038,8 +120065,8 @@ function Update-SqlPermission {
}
}

$null = $sourceDb.Parent.ConnectionContext.Disconnect()
$null = $destDb.Parent.ConnectionContext.Disconnect()
$null = $sourceDb.Parent.ConnectionContext.SqlConnectionObject.Close()
$null = $destDb.Parent.ConnectionContext.SqlConnectionObject.Close()
# Remove Connect, Alter Any Assembly, etc
$destPerms = $destDb.EnumDatabasePermissions($userName)
$perms = $sourceDb.EnumDatabasePermissions($userName)
Expand Down Expand Up @@ -120071,8 +120098,8 @@ function Update-SqlPermission {
}

# Adding database mappings and securables
$null = $SourceLogin.Parent.ConnectionContext.Disconnect()
#$null = $DestServer.ConnectionContext.Disconnect()
$null = $SourceLogin.Parent.ConnectionContext.SqlConnectionObject.Close()
$null = $DestServer.ConnectionContext.SqlConnectionObject.Close()

foreach ($db in $SourceLogin.EnumDatabaseMappings()) {
$dbName = $db.DbName
Expand Down Expand Up @@ -120121,9 +120148,10 @@ function Update-SqlPermission {
}
}

$sourceDb.Parent.ConnectionContext.Disconnect()
# Database Roles: db_owner, db_datareader, etc
foreach ($role in $sourceDb.Roles) {
$null = $sourceDb.Parent.ConnectionContext.SqlConnectionObject.Close()
$null = $destDb.Parent.ConnectionContext.SqlConnectionObject.Close()
if ($role.EnumMembers() -contains $userName) {
$roleName = $role.Name
$destDbRole = $destDb.Roles[$roleName]
Expand All @@ -120143,6 +120171,7 @@ function Update-SqlPermission {
}

# Connect, Alter Any Assembly, etc
$null = $sourceDb.Parent.ConnectionContext.SqlConnectionObject.Close()
$perms = $sourceDb.EnumDatabasePermissions($userName)
foreach ($perm in $perms) {
$permState = $perm.PermissionState
Expand Down
2 changes: 1 addition & 1 deletion dbatools.psd1
Expand Up @@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '0.9.825'
ModuleVersion = '0.9.826'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
Expand Down

0 comments on commit 1a713ee

Please sign in to comment.