Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions project/dbatools.computer/Commands/SetDbaPrivilegeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public sealed class SetDbaPrivilegeCommand : DbaBaseCmdlet
$strSID.Value
}";

// The three Invoke-Command2 -Raw scriptblocks, verbatim from the PS source (comments included).
// The three Invoke-Command2 -Raw scriptblocks, verbatim from the PS source (comments
// included), except MainScript's /db path and CleanupScript's extra Remove-Item - see the
// secedit.sdb/.jfm fix note on CleanupScript below. The retired PS source (dbatools/private/
// retired/Set-DbaPrivilege.ps1) still carries the original bug; it is dead code, not shipping.
private const string ExportScript = @"
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd(""""); secedit /export /cfg $temp\secpolByDbatools.cfg > $NULL;
";
Expand Down Expand Up @@ -198,10 +201,14 @@ public sealed class SetDbaPrivilegeCommand : DbaBaseCmdlet
}
}
}
$null = secedit /configure /cfg $tempfile /db secedit.sdb /areas USER_RIGHTS /overwrite /quiet
$null = secedit /configure /cfg $tempfile /db $temp\secedit.sdb /areas USER_RIGHTS /overwrite /quiet
";

private const string CleanupScript = @" $temp = ([System.IO.Path]::GetTempPath()).TrimEnd(""""); Remove-Item $temp\secpolByDbatools.cfg -Force > $NULL ";
// secedit /configure /db resolves a bare filename against the process's current directory,
// not $temp - a relative "secedit.sdb" left secedit.sdb/.jfm wherever the caller's shell
// happened to be running. Point /db at $temp and clean up the database and its journal file
// alongside the exported cfg.
private const string CleanupScript = @" $temp = ([System.IO.Path]::GetTempPath()).TrimEnd(""""); Remove-Item $temp\secpolByDbatools.cfg -Force > $NULL; Remove-Item $temp\secedit.sdb, $temp\secedit.jfm -Force -ErrorAction SilentlyContinue > $NULL ";

// PS begin block: $ComputerName = $ComputerName.ComputerName | Select-Object -Unique. The
// variable keeps its [DbaInstanceParameter[]] type constraint, so the unique ComputerName
Expand Down
Loading