This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| [name] AS database_name, is_auto_shrink_on | |
| , 'ALTER DATABASE [' + [name] + ']' + ' SET AUTO_SHRINK OFF;' AS alter_command | |
| FROM sys.databases | |
| WHERE [name] NOT IN ('master','model','msdb','tempdb') | |
| AND state_desc = 'ONLINE' | |
| AND is_auto_shrink_on = 1 | |
| ORDER BY [name] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $instance = 'localhost' | |
| $logins = 'group1','group2' | |
| foreach ($login in $logins) | |
| { | |
| Write-Output "Processing $login" | |
| #$file = "C:\temp\backup-$($login.Replace('\','_')).sql" | |
| #Export-DbaLogin -SqlInstance $instance -Login $login -FilePath $file -ObjectLevel | |
| Remove-DbaDbUser -SqlInstance $instance -User $login -Force | |
| Remove-DbaLogin -SqlInstance $instance -Login $login -Force -Confirm:$false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @StartSearchDate datetime; | |
| DECLARE @SecondsAround int; | |
| DECLARE @Databases TABLE (DatabaseName sysname NOT NULL PRIMARY KEY); | |
| SET @StartSearchDate = GETDATE() - 2; | |
| SET @SecondsAround = 1; | |
| -- | |
| -- Get error logs | |
| -- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @original_path sysname = N'E:\SQLServer\MSSQL15.SQL2022\MSSQL\DATA'; | |
| DECLARE @destination_path sysname = N'E:\SQLServer\MSSQL16.SQL2022\MSSQL\DATA'; | |
| DECLARE @sqlcmd nvarchar(max) = ( | |
| SELECT | |
| N'ALTER DATABASE [tempdb]' | |
| + N' MODIFY FILE (NAME = [' + [name] + ']' | |
| + N', FILENAME = ''' + REPLACE(physical_name, @original_path, @destination_path) + ''');' | |
| + CHAR(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| USE [msdb] | |
| GO | |
| /****** Object: Alert [AG Connection Timeout] Script Date: 1/13/2023 10:36:31 AM ******/ | |
| EXEC msdb.dbo.sp_add_alert @name=N'AG Connection Timeout', | |
| @message_id=35206, | |
| @severity=0, | |
| @enabled=1, | |
| @delay_between_responses=60, | |
| @include_event_description_in=1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT DISTINCT | |
| RP.[name] | |
| , RP.[type_desc] AS role_type | |
| , PM.class_desc AS permission_type | |
| , PM.[permission_name] | |
| , pm.state_desc | |
| , CASE | |
| WHEN O1.type_desc IS NULL OR O1.type_desc = 'SYSTEM_TABLE' | |
| THEN PM.class_desc | |
| ELSE O1.[type_desc] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Note This script creates two stored procedures in the master database. The procedures are named sp_hexadecimal and sp_help_revlogin. */ | |
| -- Create stored procedure sp_hexadecimal | |
| USE master | |
| GO | |
| IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL | |
| DROP PROCEDURE sp_hexadecimal | |
| GO | |
| CREATE PROCEDURE sp_hexadecimal | |
| @binvalue varbinary(256), | |
| @hexvalue varchar (514) OUTPUT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $scanPSTExe = "C:\Program Files\Microsoft Office\root\Office16\SCANPST.EXE" | |
| $SourceDir = "E:\Outlook\test" | |
| $BackupDir = "F:\Backups\Outlook\test" | |
| $MaxIterations = 10 | |
| $PSTs = Get-ChildItem -Path (Join-Path $SourceDir "\*") -Include *.pst,*.ost -File | |
| $PSTs | ForEach-Object { | |
| $NumIteration = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @old_email_address nvarchar(128) = N'noreply@foobar.org'; | |
| DECLARE @new_email_address nvarchar(128) = N'sqlmail@foobar.org'; | |
| DECLARE @old_replyto_address nvarchar(128) = N'noreply@foobar.org'; | |
| DECLARE @new_replyto_address nvarchar(128) = N'sqlmail@foobar.org'; | |
| DECLARE @test_email_address nvarchar(128) = N'admin@foobar.org'; | |
| USE msdb; | |
| SET NOCOUNT ON; | |
| IF OBJECT_ID('tempdb..#tmp_account') IS NOT NULL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| FLOOR(transferred_size_bytes * 1. / NULLIF(database_size_bytes, 0) * 100) AS Perc | |
| , transfer_rate_bytes_per_second / 1024 / 1024. AS MBSec | |
| , internal_state_desc | |
| , start_time_utc, estimate_time_complete_utc | |
| , FLOOR(transferred_size_bytes / 1024. / 1024. / 1024.) AS transferred_size_GB | |
| , FLOOR(database_size_bytes / 1024. / 1024. / 1024.) AS database_size_bytes_GB | |
| , * | |
| FROM sys.dm_hadr_physical_seeding_stats |
NewerOlder