Skip to content

Instantly share code, notes, and snippets.

View ghotz's full-sized avatar

Gianluca Hotz ghotz

View GitHub Profile
@ghotz
ghotz / check-governor-memory.sql
Created March 20, 2015 12:28
Quick Check Resource Governor
SELECT * FROM sys.dm_exec_query_resource_semaphores WHERE pool_id = 1
SELECT S1.session_id, S1.[host_name], S1.[program_name], S1.login_name
, R1.command, R1.status, R1.wait_type, R1.wait_time, R1.last_wait_type, R1.wait_resource
, M1.*
FROM sys.dm_exec_sessions AS S1
JOIN sys.dm_exec_requests AS R1
ON S1.session_id = R1.session_id
LEFT
JOIN sys.dm_exec_query_memory_grants AS M1
@ghotz
ghotz / xe_audit_db_ntauth_applications_2012.sql
Created April 21, 2015 21:54
Audit applications that connect to a SQL Server database using Integrated Authentication
--
-- Audit applications that connects to a specified database using
-- Windows Integrated Authentication storing the applications names
-- and the number of connections.
--
-- Requires SQL Server version >= 2012
-- Activate SQLCMD mode before running
--
:setvar DatabaseName TestDatabase
@ghotz
ghotz / en_profile_logons.sql
Created April 21, 2015 21:57
Profile SQL Server connections using Event Notification and AUDIT_LOGIN events
--
-- Profile connections using Event Notification and AUDIT_LOGIN events
-- to create a summary of number of logins by database, application, login and hostname
-- additionally tracking domain name and user
--
USE DBPerfmon
GO
-- Prerequisites
ALTER DATABASE DBPerfmon SET ENABLE_BROKER;
@ghotz
ghotz / rename-perfmon.ps1
Created July 14, 2015 11:21
Rename and moves perfmon logs formatted with a certain pattern
# Normalizes perfmon logs names given a set of directories
# following the pattern COMPUTERNAME_YYYYMMDD-NNNNNN
# by moving log files to the root dir and assigning a unique name
$PALDir = "D:\Temp\PAL"
Get-ChildItem $PALDir -Directory |
? { $_.Name -match "(?<ComputerName>\w*)_(?<ISODate>\d{4}\d{2}\d{2})-(?<Sequence>\d{6})" } |
% {
$file = Get-ChildItem $_.FullName;
$file.MoveTo($PALDir + "\" + $Matches["ComputerName"] + "_PAL_" + $Matches["ISODate"] + "_" + $Matches["Sequence"]+".blg");
@ghotz
ghotz / Get-ASDBSizes.ps1
Created July 15, 2015 10:14
Get Analysis Services databases size
Param($ServerName="GSRVBI1")
cls
$loadInfo = [Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($ServerName)
if ($server.name -eq $null) {
Write-Output ("Server [{0}] not found" -f $ServerName)
break
}
@ghotz
ghotz / server-info.sql
Created September 23, 2015 08:13
Gather SQL Server services information
SELECT DSS.servicename,
DSS.startup_type_desc,
DSS.status_desc,
DSS.last_startup_time,
DSS.service_account,
DSS.is_clustered,
DSS.cluster_nodename,
DSS.filename,
DSS.startup_type,
DSS.status,
@ghotz
ghotz / check-camera-roll.ps1
Created September 29, 2015 05:59
Checks that all pictures from a Windows Phone Lumia 1020 have been uploaded to OneDrive
#
# This script checks that all pictures from a Windows Phone Lumia 1020
# have been uploaded to OneDrive.
#
# It takes a local backup of the phone's Camera Roll directory copied directly
# from the phone and checks that all pictures are present in Onedrive's local
# copy of the Camera Roll directory.
#
# Note: the scripts assumes hires copies are automatically uploaded and
# removes pictures that are already present without the __highres suffix
@ghotz
ghotz / exiftool-example-argsfile.ps1
Last active September 15, 2023 21:00
PowerShell examples to feed arguments to Exiftool without the initialization overhead of launching the process each time
#
# Exiftool example to process multiple commands without paying the initialization time
# for each call writing to an argument file
#
cls;
$Inputdir = "C:\Photos\Personal\[2007]\[2007-00-00] Test & Test"
# initializes argument file
if (Test-Path c:\temp\tmp.args) { del c:\temp\tmp.args; };
$null | Out-File c:\temp\tmp.args -Append -Encoding Ascii;
@ghotz
ghotz / evaluate-size-growth.sql
Last active May 17, 2024 08:05
Evaluate and standardize database size and growth
SELECT DB_NAME(F.database_id) AS database_name, F.[name] as logical_filename, type_desc
, CAST(CAST(size as bigint) * 8192 / 1024. /1024. AS decimal(15,2)) AS size_mb
, is_percent_growth
, CASE is_percent_growth WHEN 0 THEN CAST(CAST(growth as bigint) * 8192 / 1024. /1024. AS decimal(15,2)) END AS growth_mb
, CASE is_percent_growth WHEN 1 THEN growth END AS growth_percent
, 'ALTER DATABASE [' + DB_NAME(F.database_id) + '] MODIFY FILE (NAME = ''' + F.[name] + ''''
+ CASE
WHEN type_desc = 'LOG' AND (CAST(size as bigint) * 8192) < (256*1024*1024) THEN ', SIZE = 64MB'
ELSE ''
END
@ghotz
ghotz / convert-polarflow-to-garmin.ps1
Created November 7, 2015 22:42
Converts Polar Flow TCX file for Garmin Connect
#
# Removes incorrect data from *.tcx files exported from the Polar Flow
# web site so they can be uploaded to the Garmin web site.
# More info: https://forums.garmin.com/showthread.php?165708-Polar-Flow-TCX-export-to-Garmin-Connect
#
$SourceDir = "C:\Users\Gianluca\OneDrive\Documents\Health\PolarFlow";
$DestinationDir = "C:\Users\Gianluca\OneDrive\Documents\Health\ExportGarmin";
Get-ChildItem $SourceDir -Include "*.tcx" -Recurse |
Where-Object { !(Test-Path (Join-Path $DestinationDir $_.Name)) } |