Skip to content

Instantly share code, notes, and snippets.

View tcartwright's full-sized avatar

Tim Cartwright tcartwright

  • Houston, Texas
View GitHub Profile
@tcartwright
tcartwright / SQLAgentScripter.ps1
Created August 22, 2021 22:00
POWERSHELL: Generates SQL Server Agent objects to sql files
[cmdletbinding()]
Param(
[Parameter(Mandatory=$true)]
[string[]]$servers,
[ValidateScript({
if(-Not ($_ | Test-Path )) {
throw "Folder does not exist"
}
return $true
@tcartwright
tcartwright / DownloadPackage.ps1
Last active October 13, 2021 22:38
POWERSHELL: Download package recursively. Is able to work even when Install-Package hits a dependency loop.
Param(
[Parameter(Mandatory=$true)]
[string] $PackageName,
[string] $PackageVersion = "0.0.0",
[string] $PackageDestination
)
Clear-Host
<#
NOTES: You really should use:
@tcartwright
tcartwright / XmlTreePackage.ps1
Created August 22, 2021 19:16
POWERSHELL: Will generate an xml tree for a package and its dependencies. Can also be used to track down package recursive loops.
Param(
[Parameter(Mandatory=$true)]
[string] $PackageName,
[string] $PackageVersion = "0.0.0"
)
Clear-Host
#use this to retain what we have packagesList previously so we dont have to find it again
$packagesList = @{}
@tcartwright
tcartwright / TreePackage.ps1
Last active August 22, 2021 19:22
POWERSHELL: Will write out a tree structure for NUGET packages so their hierarchy can be visualized.
Param(
[Parameter(Mandatory=$true)]
[string] $PackageName,
[string] $PackageVersion = "0.0.0"
)
Clear-Host
#use this to retain what we have packagesList previously so we dont have to find it again
$packagesList = @{}
$sep = "*" * 80
@tcartwright
tcartwright / InstallPackageRecursive.ps1
Last active August 22, 2021 03:30
POWERSHELL: Install packages recursively
Clear-Host
#use this to retain what we have packagesList previously so we dont download again
$packagesList = @{}
$installed = @{}
$alreadyInstalled = @{}
function VersionCompare($version1, $version2) {
$version1 = $version1 -split "-", 2
$version2 = $version2 -split "-", 2
@tcartwright
tcartwright / TestConnectonStringCharacters.ps1
Last active August 19, 2021 22:26
SQL SERVER: Demonstrates how special characters are handled properly if you use the appropriate connection string builder
<#
Notice:
- That when there are special characters in the password, that it defaults to wrapping the password with "
- Except when already wrapped with single quotes, and a " is placed in the middle
- When a " or ' and the password is not wrapped, then the " is replaced with "" and the password is wrapped with ""
- This all depends upon the builder as well. Each connection string builder can havedifferent special characters.
- I highly suggest using the appropriate connection string builder for the appropriate provider.
- Derived https://docs.microsoft.com/en-us/dotnet/api/system.data.common.dbconnectionstringbuilder?view=net-5.0
- System.Data.EntityClient.EntityConnectionStringBuilder
- System.Data.Odbc.OdbcConnectionStringBuilder
@tcartwright
tcartwright / HierarchicalXmlListofTriggerEventTypes.sql
Last active August 26, 2021 13:34
SQL SERVER: Hierarchical view of trigger event types
IF OBJECT_ID('dbo.fn_trigger_event_types') IS NOT NULL BEGIN
DROP FUNCTION dbo.fn_trigger_event_types
END
GO
CREATE FUNCTION dbo.fn_trigger_event_types (@parent_type INT) RETURNS XML
BEGIN RETURN
(SELECT [trigger_event_type].type_name,
dbo.fn_trigger_event_types([trigger_event_type].type)
FROM sys.trigger_event_types AS [trigger_event_type]
@tcartwright
tcartwright / block_control_trigger.sql
Last active August 19, 2021 14:48
SQL SERVER: Blocks GRANT / REVOKE CONTROL for non sysadmins who are security admins.
USE [master]
GO
IF EXISTS (SELECT 1 FROM sys.server_triggers WHERE name = 'block_control_trigger') BEGIN
DROP TRIGGER [block_control_trigger] ON ALL SERVER
END
GO
CREATE TRIGGER [block_control_trigger]
ON ALL SERVER
@tcartwright
tcartwright / BuildPackageAndPushSolution.bat
Last active August 19, 2021 20:40
POWERSHELL: Build Package and Push (similar to dotnet build|package|push) for old school projects and nuspec files
@rem bat file to ease use of the script
@%~d0
@cd "%~dp0"
powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile ^
-file "%~dpn0.ps1" ^
-SolutionPath "path to .sln" ^
-NuspecPath "path to .nuspec" ^
-NugetSource "http://nuget.server.com" ^
@tcartwright
tcartwright / RunNugetCommandLine.ps1
Last active August 14, 2021 17:09
POWERSHELL: Running nuget command line from powershell
Clear-Host
# https://docs.microsoft.com/en-us/nuget/reference/nuget-exe-cli-reference
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Package NuGet.CommandLine -Scope CurrentUser -Force
$package = Get-Package NuGet.CommandLine