SQL Server
-
Test LSN Chain
Quick not fully tested script to check whether a set of provided backup files contain a valid log sequence number chain. Continue reading
-
Change Sql Service Account Password with no Restart
On SINGLE INSTANCE (apparently this does not work correctly with clusters…will test and update…) Sql Servers use the following code to update the password for the service account. This will not require a restart of the service. Curiously…the call to $service.ChangePassword is supposed to take the old password as the first parameter and the new… Continue reading
-
Set Sql Server\Agent Service Account
This uses a CIMMethod to change the service accounts. The Wmi.ManagedComputer method is also included in the comments below…but I’ve found this to be not reliable at times. Continue reading
-
Enable Sql AlwaysOn
This always seems to give me trouble, and I always forget the manner in which I run this that works correctly, so, viola! Continue reading
-
Restore Database with SMO
Probably 3 or 4 versions of this already on here. So here is one more. Continue reading
-
Capture Sql Server Information Messages in Powershell
Sometimes you have a need to capture the informational messages generated in sql server, for example sp_help_revlogin only prints the user information to the messages tab. Import-Module SqlServer -DisableNameChecking cls try { $users = @(‘user1’, ‘user2’) $users | % { $user = $_ $sqlConn = New-Object System.Data.SqlClient.SqlConnection “Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=servername” $handler =… Continue reading
-
Stop/Disable SqlAgent/MSSQLServer service via Powershell
One-liner to stop and disable the sqlagent and msssqlserver service. Get-Service MSSQLSERVER, SQLSERVERAGENT | Stop-Service -PassThru -Force | Set-Service -StartupType disabled Continue reading
Meh.