Skip to content

Commit 918182a

Browse files
Merge branch 'development'
2 parents 72a7a40 + a85b606 commit 918182a

File tree

5 files changed

+113
-103
lines changed

5 files changed

+113
-103
lines changed

Diff for: bin/dbatools-buildref-index.json

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"LastUpdated": "2024-07-24T00:00:00",
2+
"LastUpdated": "2024-09-11T00:00:00",
33
"Data": [
44
{
55
"Version": "8.0.47",
@@ -4119,6 +4119,10 @@
41194119
"Version": "13.0.6441",
41204120
"KBList": "5040946"
41214121
},
4122+
{
4123+
"Version": "13.0.6445",
4124+
"KBList": "5042207"
4125+
},
41224126
{
41234127
"Version": "13.0.7000",
41244128
"KBList": "5014242"
@@ -4139,6 +4143,10 @@
41394143
"Version": "13.0.7037",
41404144
"KBList": "5040944"
41414145
},
4146+
{
4147+
"Version": "13.0.7040",
4148+
"KBList": "5042209"
4149+
},
41424150
{
41434151
"Version": "14.0.1",
41444152
"Name": "2017"
@@ -4204,6 +4212,10 @@
42044212
"Version": "14.0.2056",
42054213
"KBList": "5040942"
42064214
},
4215+
{
4216+
"Version": "14.0.2060",
4217+
"KBList": "5042217"
4218+
},
42074219
{
42084220
"CU": "CU1",
42094221
"Version": "14.0.3006",
@@ -4399,6 +4411,10 @@
43994411
"Version": "14.0.3471",
44004412
"KBList": "5040940"
44014413
},
4414+
{
4415+
"Version": "14.0.3475",
4416+
"KBList": "5042215"
4417+
},
44024418
{
44034419
"Version": "15.0.1000",
44044420
"Name": "2019"
@@ -4448,6 +4464,10 @@
44484464
"Version": "15.0.2116",
44494465
"KBList": "5040986"
44504466
},
4467+
{
4468+
"Version": "15.0.2120",
4469+
"KBList": "5042214"
4470+
},
44514471
{
44524472
"CU": "CU1",
44534473
"Version": "15.0.4003",
@@ -4608,6 +4628,15 @@
46084628
"Version": "15.0.4382",
46094629
"KBList": "5040948"
46104630
},
4631+
{
4632+
"CU": "CU28",
4633+
"Version": "15.0.4385",
4634+
"KBList": "5039747"
4635+
},
4636+
{
4637+
"Version": "15.0.4390",
4638+
"KBList": "5042749"
4639+
},
46114640
{
46124641
"Version": "16.0.100",
46134642
"Name": "2022"
@@ -4645,6 +4674,10 @@
46454674
"Version": "16.0.1121",
46464675
"KBList": "5040936"
46474676
},
4677+
{
4678+
"Version": "16.0.1125",
4679+
"KBList": "5042211"
4680+
},
46484681
{
46494682
"CU": "CU1",
46504683
"Version": "16.0.4003",
@@ -4730,6 +4763,10 @@
47304763
"CU": "CU14",
47314764
"Version": "16.0.4135",
47324765
"KBList": "5038325"
4766+
},
4767+
{
4768+
"Version": "16.0.4140",
4769+
"KBList": "5042578"
47334770
}
47344771
]
47354772
}

Diff for: dbatools.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'dbatools.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2.1.22'
14+
ModuleVersion = '2.1.23'
1515

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

Diff for: public/Export-DbaUser.ps1

+11-6
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ function Export-DbaUser {
252252

253253
$stepCounter = 0
254254
foreach ($dbuser in $users) {
255+
# Clear output for each user
256+
$outsql = @()
257+
$sql = ""
255258

256259
if ($GenerateFilePerUser) {
257260
if ($null -eq $usersProcessed[$dbuser.Name]) {
@@ -264,7 +267,12 @@ function Export-DbaUser {
264267
}
265268
}
266269

267-
Write-ProgressHelper -TotalSteps $users.Count -Activity "Exporting from $($db.Name)" -StepNumber ($stepCounter++) -Message "Generating script ($FilePath) for user $dbuser"
270+
if ($Passthru) {
271+
$progressMessage = "Generating script for user $dbuser"
272+
} else {
273+
$progressMessage = "Generating script ($FilePath) for user $dbuser"
274+
}
275+
Write-ProgressHelper -TotalSteps $users.Count -Activity "Exporting from $($db.Name)" -StepNumber ($stepCounter++) -Message $progressMessage
268276

269277
#setting database
270278
if (((Test-Bound ScriptingOptionsObject) -and $ScriptingOptionsObject.IncludeDatabaseContext) -or - (Test-Bound ScriptingOptionsObject -Not)) {
@@ -366,7 +374,7 @@ function Export-DbaUser {
366374
$withGrant = " WITH GRANT OPTION"
367375
$grantDatabasePermission = 'GRANT'
368376
} else {
369-
$withGrant = " "
377+
$withGrant = ""
370378
$grantDatabasePermission = $databasePermission.PermissionState.ToString().ToUpper()
371379
}
372380
if ($Template) {
@@ -526,7 +534,7 @@ function Export-DbaUser {
526534
$withGrant = " WITH GRANT OPTION"
527535
$grantObjectPermission = 'GRANT'
528536
} else {
529-
$withGrant = " "
537+
$withGrant = ""
530538
$grantObjectPermission = $objectPermission.PermissionState.ToString().ToUpper()
531539
}
532540
if ($Template) {
@@ -573,9 +581,6 @@ function Export-DbaUser {
573581
$sql | Out-File -Encoding:$Encoding -FilePath $FilePath -Append
574582
}
575583
}
576-
# Clear variables for next user
577-
$outsql = @()
578-
$sql = ""
579584
} else {
580585
$sql
581586
}

Diff for: public/Get-DbaPrivilege.ps1

+62-93
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ function Get-DbaPrivilege {
5656
)
5757

5858
begin {
59-
$ResolveSID = @'
60-
function Convert-SIDToUserName ([string] $SID ) {
61-
try {
62-
$objSID = New-Object System.Security.Principal.SecurityIdentifier ($SID)
63-
$objUser = $objSID.Translate([System.Security.Principal.NTAccount])
64-
$objUser.Value
65-
} catch {
66-
$SID
67-
}
68-
}
69-
'@
59+
function Convert-SIDToUserName ([string] $SID ) {
60+
try {
61+
$objSID = New-Object System.Security.Principal.SecurityIdentifier ($SID)
62+
$objUser = $objSID.Translate([System.Security.Principal.NTAccount])
63+
$objUser.Value
64+
} catch {
65+
$SID
66+
}
67+
}
68+
7069
$ComputerName = $ComputerName.ComputerName | Select-Object -Unique
70+
7171
}
7272
process {
7373
foreach ($computer in $ComputerName) {
@@ -78,123 +78,96 @@ function Get-DbaPrivilege {
7878
}
7979

8080
try {
81-
Write-Message -Level Verbose -Message "Exporting Privileges on $computer"
82-
$null = Invoke-Command2 -Raw -ComputerName $computer -Credential $Credential -ScriptBlock {
81+
Write-Message -Level Verbose -Message "Exporting Privileges on $computer and cleaning up temporary files"
82+
$secPol = Invoke-Command2 -Raw -ComputerName $computer -Credential $Credential -ScriptBlock {
8383
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("")
8484
secedit /export /cfg $temp\secpolByDbatools.cfg > $null
85+
$CFG = Get-Content $temp\secpolByDbatools.cfg -Force
86+
Remove-Item $temp\secpolByDbatools.cfg -Force
87+
$CFG
8588
}
8689

8790
Write-Message -Level Verbose -Message "Getting Batch Logon Privileges on $computer"
88-
$bl = Invoke-Command2 -Raw -ComputerName $computer -Credential $Credential -ArgumentList $ResolveSID -ScriptBlock {
89-
param ($ResolveSID)
90-
. ([ScriptBlock]::Create($ResolveSID))
91-
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("");
92-
$blEntries = (Get-Content $temp\secpolByDbatools.cfg | Where-Object {
93-
$_ -like "SeBatchLogonRight*"
94-
})
95-
96-
if ($null -ne $blEntries) {
97-
$blEntries.Substring(20).Split(",") | ForEach-Object {
98-
if ($_ -match '^\*S-') {
99-
Convert-SIDToUserName -SID $_.TrimStart('*')
100-
} else {
101-
$_
102-
}
91+
$blEntries = $secPol | Where-Object { $_ -like "SeBatchLogonRight*" }
92+
93+
$bl = if ($null -ne $blEntries) {
94+
$blEntries.Substring(20).Split(",") | ForEach-Object {
95+
if ($_ -match '^\*S-') {
96+
Convert-SIDToUserName -SID $_.TrimStart('*')
97+
} else {
98+
$_
10399
}
104100
}
105101
}
102+
106103
if ($bl.count -eq 0) {
107104
Write-Message -Level Verbose -Message "No users with Batch Logon Rights on $computer"
108105
}
109106

110107
Write-Message -Level Verbose -Message "Getting Instant File Initialization Privileges on $computer"
111-
$ifi = Invoke-Command2 -Raw -ComputerName $computer -Credential $Credential -ArgumentList $ResolveSID -ScriptBlock {
112-
param ($ResolveSID)
113-
. ([ScriptBlock]::Create($ResolveSID))
114-
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("");
115-
$ifiEntries = (Get-Content $temp\secpolByDbatools.cfg | Where-Object {
116-
$_ -like 'SeManageVolumePrivilege*'
117-
})
118-
119-
if ($null -ne $ifiEntries) {
120-
$ifiEntries.Substring(26).Split(",") | ForEach-Object {
121-
if ($_ -match '^\*S-') {
122-
Convert-SIDToUserName -SID $_.TrimStart('*')
123-
} else {
124-
$_
125-
}
108+
$ifiEntries = $secPol | Where-Object { $_ -like 'SeManageVolumePrivilege*' }
109+
110+
$ifi = if ($null -ne $ifiEntries) {
111+
$ifiEntries.Substring(26).Split(",") | ForEach-Object {
112+
if ($_ -match '^\*S-') {
113+
Convert-SIDToUserName -SID $_.TrimStart('*')
114+
} else {
115+
$_
126116
}
127117
}
128118
}
119+
129120
if ($ifi.count -eq 0) {
130121
Write-Message -Level Verbose -Message "No users with Instant File Initialization Rights on $computer"
131122
}
132123

133124
Write-Message -Level Verbose -Message "Getting Lock Pages in Memory Privileges on $computer"
134-
$lpim = Invoke-Command2 -Raw -ComputerName $computer -Credential $Credential -ArgumentList $ResolveSID -ScriptBlock {
135-
param ($ResolveSID)
136-
. ([ScriptBlock]::Create($ResolveSID))
137-
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("");
138-
$lpimEntries = (Get-Content $temp\secpolByDbatools.cfg | Where-Object {
139-
$_ -like 'SeLockMemoryPrivilege*'
140-
})
141-
142-
if ($null -ne $lpimEntries) {
143-
$lpimEntries.Substring(24).Split(",") | ForEach-Object {
144-
if ($_ -match '^\*S-') {
145-
Convert-SIDToUserName -SID $_.TrimStart('*')
146-
} else {
147-
$_
148-
}
125+
$lpimEntries = $secPol | Where-Object { $_ -like 'SeLockMemoryPrivilege*' }
126+
127+
$lpim = if ($null -ne $lpimEntries) {
128+
$lpimEntries.Substring(24).Split(",") | ForEach-Object {
129+
if ($_ -match '^\*S-') {
130+
Convert-SIDToUserName -SID $_.TrimStart('*')
131+
} else {
132+
$_
149133
}
150134
}
151135
}
136+
152137
if ($lpim.count -eq 0) {
153138
Write-Message -Level Verbose -Message "No users with Lock Pages in Memory Rights on $computer"
154139
}
155140

156141
Write-Message -Level Verbose -Message "Getting Generate Security Audits Privileges on $computer"
157-
$gsa = Invoke-Command2 -Raw -ComputerName $computer -Credential $Credential -ArgumentList $ResolveSID -ScriptBlock {
158-
param ($ResolveSID)
159-
. ([ScriptBlock]::Create($ResolveSID))
160-
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("");
161-
$gsaEntries = (Get-Content $temp\secpolByDbatools.cfg | Where-Object {
162-
$_ -like 'SeAuditPrivilege*'
163-
})
164-
165-
if ($null -ne $gsaEntries) {
166-
$gsaEntries.Substring(19).Split(",") | ForEach-Object {
167-
if ($_ -match '^\*S-') {
168-
Convert-SIDToUserName -SID $_.TrimStart('*')
169-
} else {
170-
$_
171-
}
142+
$gsaEntries = $secPol | Where-Object { $_ -like 'SeAuditPrivilege*' }
143+
144+
$gsa = if ($null -ne $gsaEntries) {
145+
$gsaEntries.Substring(19).Split(",") | ForEach-Object {
146+
if ($_ -match '^\*S-') {
147+
Convert-SIDToUserName -SID $_.TrimStart('*')
148+
} else {
149+
$_
172150
}
173151
}
174152
}
153+
175154
if ($gsa.count -eq 0) {
176155
Write-Message -Level Verbose -Message "No users with Generate Security Audits Rights on $computer"
177156
}
178157

179158
Write-Message -Level Verbose -Message "Getting Logon as a service Privileges on $computer"
180-
$los = Invoke-Command2 -Raw -ComputerName $computer -Credential $Credential -ArgumentList $ResolveSID -ScriptBlock {
181-
param ($ResolveSID)
182-
. ([ScriptBlock]::Create($ResolveSID))
183-
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("");
184-
$losEntries = (Get-Content $temp\secpolByDbatools.cfg | Where-Object {
185-
$_ -like "SeServiceLogonRight*"
186-
})
187-
188-
if ($null -ne $losEntries) {
189-
$losEntries.Substring(22).split(",") | ForEach-Object {
190-
if ($_ -match '^\*S-') {
191-
Convert-SIDToUserName -SID $_.TrimStart('*')
192-
} else {
193-
$_
194-
}
159+
$losEntries = $secPol | Where-Object { $_ -like "SeServiceLogonRight*" }
160+
161+
$los = if ($null -ne $losEntries) {
162+
$losEntries.Substring(22).split(",") | ForEach-Object {
163+
if ($_ -match '^\*S-') {
164+
Convert-SIDToUserName -SID $_.TrimStart('*')
165+
} else {
166+
$_
195167
}
196168
}
197169
}
170+
198171
if ($los.count -eq 0) {
199172
Write-Message -Level Verbose -Message "No users with Logon as a service Rights on $computer"
200173
}
@@ -211,11 +184,7 @@ function Get-DbaPrivilege {
211184
LogonAsAService = $los -contains $_
212185
}
213186
}
214-
Write-Message -Level Verbose -Message "Removing secpol file on $computer"
215-
Invoke-Command2 -Raw -ComputerName $computer -Credential $Credential -ScriptBlock {
216-
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("")
217-
Remove-Item $temp\secpolByDbatools.cfg -Force
218-
}
187+
219188
} catch {
220189
Stop-Function -Continue -Message "Failure" -ErrorRecord $_ -Target $computer
221190
}

Diff for: public/Reset-DbaAdmin.ps1

+1-2
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ function Reset-DbaAdmin {
311311
}
312312
} catch {
313313
Stop-Service -InputObject $sqlservice -Force -ErrorAction SilentlyContinue
314-
315314
if ($isClustered) {
316315
$clusterResource | Where-Object Name -EQ "SQL Server" | ForEach-Object { $_.BringOnline(60) }
317316
$clusterResource | Where-Object Name -NE "SQL Server" | ForEach-Object { $_.BringOnline(60) }
@@ -332,7 +331,7 @@ function Reset-DbaAdmin {
332331
Start-Sleep 3
333332
$null = Invoke-ResetSqlCmd -instance $instance -Sql "SELECT 1" -EnableException
334333
} catch {
335-
Stop-Service Input-Object $sqlservice -Force -ErrorAction SilentlyContinue
334+
Stop-Service -InputObject $sqlservice -Force -ErrorAction SilentlyContinue
336335
if ($isClustered) {
337336
$clusterResource | Where-Object { $_.Name -eq "SQL Server" } | ForEach-Object { $_.BringOnline(60) }
338337
$clusterResource | Where-Object { $_.Name -ne "SQL Server" } | ForEach-Object { $_.BringOnline(60) }

0 commit comments

Comments
 (0)