Skip to content

Instantly share code, notes, and snippets.

@JayHollingum
JayHollingum / extended-event-queries-completed.sql
Created May 8, 2019 12:11
Script for creating an Extended Event on SQL Server to track completed queries
IF EXISTS (select * fROM sys.dm_xe_sessions where name = 'QueriesCompleted')
BEGIN
DROP EVENT SESSION [QueriesCompleted] ON SERVER
END
GO
CREATE EVENT SESSION [QueriesCompleted] ON SERVER
ADD EVENT sqlserver.rpc_completed(
ACTION(
sqlserver.client_app_name,
@JayHollingum
JayHollingum / alter-encoding.ps
Created November 20, 2019 20:52
PowerShell 6 script to bulk update file encoding
Get-ChildItem -Path C:\some-dir\* -Include *.ext -Recurse | ForEach-Object {
$content = Get-Content $_.FullName
$content | Out-File -Encoding UTF8NoBOM $_.FullName
#write-host "Encoding changed:" $_.FullName
}
git merge -Xtheirs branch-to-merge
git mv -k * ./dir-to-move-to
@JayHollingum
JayHollingum / git remove files with specific extension
Created December 4, 2019 09:54
Remove files with a specific extension. -r switch for subdirectories.
git rm -r '*.ext'
@JayHollingum
JayHollingum / sql-server-edition-version.sql
Last active April 22, 2022 13:48
Get the version, edition, and expiry data if evaluation for SQL Server
select
SERVERPROPERTY('ProductVersion') AS ProductVersion,
SERVERPROPERTY('ProductLevel') AS ProductLevel,
SERVERPROPERTY('Edition') AS Edition,
create_date AS 'SQLServerInstallDate',
case
when CAST(SERVERPROPERTY('Edition') as nvarchar(100)) like '% evaluation %' then
DATEADD(day, 180, create_date) --evaluation periods for 180 days
else
''
@JayHollingum
JayHollingum / self-signed-cert.ps1
Created June 23, 2020 00:05
Powershell script to generate self signed cert for server
New-SelfSignedCertificate -FriendlyName "FTP Server" -CertStoreLocation cert:\localmachine\my -DnsName name.of.machine.com
@JayHollingum
JayHollingum / sql-server-db-list-state-recovery-mode.sql
Last active April 22, 2022 14:03
SQL Server DB List - State and Recovery Mode
use [master]
select
db.name,
db.state_desc,
db.recovery_model_desc
from
sys.databases db
where
db.name not in ('master','tempdb','model','msdb')
@JayHollingum
JayHollingum / sql-server-list-db-log-files-output-simple-mode-and-shrink.sql
Created April 22, 2022 14:27
SQL Server - list db log files and generate script to switch to simple mode and shrink
select
db.name,
db.state_desc,
db.recovery_model_desc,
mf.type_desc,
mf.physical_name,
(mf.size * 8)/1024 as SizeMB,
'USE [master]; ALTER DATABASE [' + db.name + '] SET RECOVERY SIMPLE WITH NO_WAIT; USE [' + db.name + ']; DBCC SHRINKFILE (N''' + mf.name + ''' , 0, TRUNCATEONLY);' as SQLOutput
from
sys.databases db
@JayHollingum
JayHollingum / gist:7a61430929bfb822eef59dea08d444e7
Created April 17, 2023 23:06
Fix .NET8 Preview _Host Routing Internal Server Error
<PropertyGroup>
<UseRazorSourceGenerator>false</UseRazorSourceGenerator>
</PropertyGroup>