🕵️♂️
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
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp; | |
CREATE TABLE #tmp (DBName SYSNAME, SchemaName SYSNAME, TableName SYSNAME, IndexName SYSNAME NULL, RowsCount INT, IndexSizeKB INT, UpdatesCount INT NULL, DropCMD NVARCHAR(MAX), TableCreatedDate DATETIME NULL, LastStatsDate DATETIME); | |
INSERT INTO #tmp(DBName, SchemaName, TableName, IndexName, RowsCount, IndexSizeKB, DropCMD, LastStatsDate, TableCreatedDate, UpdatesCount) | |
EXEC sp_MSforeachdb N' | |
IF EXISTS (SELECT * FROM sys.databases WHERE database_id > 4 AND name = ''?'' AND state_desc = ''ONLINE'' AND DATABASEPROPERTYEX([name], ''Updateability'') = ''READ_WRITE'') | |
BEGIN | |
USE [?]; | |
PRINT DB_NAME(); | |
SELECT |
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
# Source: https://www.sentryone.com/blog/powershell-gui-to-script-back-to-gui | |
# GUI generated using POSHGUI: https://poshgui.com/ | |
Add-Type -AssemblyName System.Windows.Forms | |
[System.Windows.Forms.Application]::EnableVisualStyles() | |
$Form = New-Object system.Windows.Forms.Form | |
$Form.ClientSize = '600,800' | |
$Form.text = "Form" | |
$Form.TopMost = $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
/* | |
Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com) | |
Date: 2020-01-28 | |
Description: | |
This script generates commands to implement a minimal standardization of all database files in the instance. | |
List of implemented standards: | |
1. Files must not be allowed to have percentage growth (defaults to 1GB growth instead as a replacement) | |
2. Files must all have UNLIMITED max size | |
3. Log files must be at least 64MB in size | |
4. Log file auto-growth must be in power multiples of 2 between 64MB and 2048MB (i.e. 64,128,256,512,1024,2048) (defaults to 1GB growth instead as a replacement) |
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
/* | |
---------------------------------------------------------------------------- | |
Shrink a Database File in Specified Increments | |
---------------------------------------------------------------------------- | |
Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com) | |
Creation Date: 2020-01-05 | |
Last Update: 2020-08-23 | |
---------------------------------------------------------------------------- | |
Description: | |
This script uses small intervals to shrink a file (in the current database) |
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
Param | |
( | |
[string] $SourceFolder = "C:\SSRS\My-Reports", | |
[string] $TargetReportServerUri = "http://localhost:8081/ReportServer", | |
[PSCredential] $Credential, | |
[switch] $CustomAuthentication, | |
[string] $ApiVersion, | |
[string] $TargetFolder = "/My-Reports/Sample-Reports", | |
[switch] $Recursive, | |
[string] $OverrideDataSourcePathForAll, #= "/My-Reports/Data Sources/ProdDS", |
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
/* | |
Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com) | |
Description: Create a Linked Server to a remote SQL Server, but give it a different name than its actual address | |
*/ | |
DECLARE | |
@ServerAddress [nvarchar](255) = 'MyRemoteServerAddress\SomeNamedInstanceIfYouWant,1433', | |
@NewServerName [nvarchar](255) = 'MyRemoteServerName', | |
@RemoteUser [nvarchar](128) = 'remote_user', | |
@RemotePassword [nvarchar](128) = 'remote_user_password', | |
@MapLocalLogin [nvarchar](255) = NULL -- name a local login to map to the remote login. If NULL, will map current login |
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
# Author: Nathan Lifshes | |
# Date: 2020-01-13 | |
Param ( | |
[string] $SrcServer , | |
[string] $SrcDatabase , | |
[string] $DestServer , | |
[string] $DestDatabase , | |
[string] $SrcUsername = "" , | |
[string] $SrcPassword = "" , | |
[string] $DestUsername = "" , |
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
CREATE EVENT SESSION [TrackFailedLogins] ON SERVER | |
ADD EVENT sqlserver.error_reported( | |
ACTION(sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.nt_username,sqlserver.database_id,sqlserver.session_id) | |
WHERE (([severity]=(20) OR [severity]=(14) OR [severity]=(16)) | |
AND ([error_number]=(18056) | |
OR [error_number]=(17892) | |
OR [error_number]=(18061) | |
OR [error_number]=(18452) | |
OR [error_number]=(11248) | |
OR [error_number]=(17806) |
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
-- Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com) | |
-- Description: Get a single row per each high severity error from the SQL Server Error Log | |
DECLARE | |
@SampleTime DATETIME = DATEADD(MINUTE,-30,SYSDATETIME()) | |
, @MinimumSeverity INT = 17 | |
, @MaximumSeverity INT = 25; | |
IF OBJECT_ID(N'tempdb..#errors') IS NOT NULL | |
DROP TABLE #errors; |
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
-- Author: Eitan Blumin | https://www.eitanblumin.com | |
-- Date: 2020-02-26 | |
-- Description: This is a query to generate rename commands for all system-named default constraints within the current database. | |
-- The constraints are renamed based on convention of "DF_{TableName}_{ColumnName}" | |
-- Simply run this query and then copy & paste the entire remediationCommand column to get the script(s). | |
SELECT | |
schemaName = sch.[name], | |
tableName = tab.[name], | |
columnName = col.[name], |