Wednesday, September 13, 2017

Recover a SQL Database that you dont have access to


If you don't have SQL access, but have local server Administrator access, do the following:

Open SQL Server Configuration Manager
  • Stop the SQL Server Instance you need to recover the SA password
  • Open the properties on the SQL Server Instance and click on the Advanced tab
  • Change the Startup parameter by adding -m; at the begging of the line and click OK
  • Start the SQL Service Instance
NOTE: exactly like this "-m;"

Open the command prompt
Run sqlcmd
Run the following command to add an existing account to the sysadmin server role.

EXEC sp_addsrvrolemember 'YourDomainName\YourUserName', 'sysadmin';
GO

Make sure: SQL Browser service is running. Remove -m; after you have done and restart SQL

Works a charm !

https://community.spiceworks.com/how_to/22044-recover-sa-password-on-microsoft-sql-server

Easy powershell function to resolve SIDs to SamAccountNames

Powershell function:

Function f-sid {
param ( [Parameter(Mandatory=$true)][String]$Sid)
$objSID = New-Object System.Security.Principal.SecurityIdentifier($Sid)
Try {
($objSID.Translate( [System.Security.Principal.NTAccount])).value
}
Catch {
Write-host “`nCouldn’t find any entry matching SID : $Sid” -foregroundcolor cyan
}
}


To use it:

> f-sid [yourSID]

if you have a list of SIDs in a txt file SIDs.txt

> get-content SIDs.txt | % { f-sid $_ }


NOTE: I did not write this, Brian did.

https://blogs.msmvps.com/ad/blog/2010/10/07/using-powershell-to-resolve-sids-to-friendly-names-2/

Thanks Brian.

Blog Archive