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 / GenerateMarkdown.ps1
Last active April 9, 2025 14:57
POWERSHELL: Generate markdown from query
Clear-Host
# UPDATE QUERY / SERVER / DB
$serverInstance = "..."
$database = "..."
$query = "
SELECT * FROM sys.tables
"
# UPDATE QUERY / SERVER / DB
@tcartwright
tcartwright / FromProcedure.sql
Last active April 8, 2025 18:01
SQL: Generate Dapper Params from SQL Server Objects
DECLARE @procedure_name sysname = 'dbo.procedure_name'
SELECT
OBJECT_SCHEMA_NAME([p].[object_id]) AS [schema],
OBJECT_NAME([p].[object_id]) AS [procedure_name],
[p].[name] AS [parameter_name],
CONCAT('sqlParams.Add("', [p].[name] ,'", ', [p].[name], ', ', [fn].db_type, ');')
FROM sys.[parameters] AS [p]
INNER JOIN sys.[types] AS [t]
ON [p].[system_type_id] = [t].[system_type_id]
AND [p].[user_type_id] = [t].[user_type_id]
@tcartwright
tcartwright / ColumnAliasing.sql
Last active March 21, 2025 19:07
SQL SERVER: The various ways to alias a column
-- Examples of the various ways to alias columns. All other methods except for #1 are deprectated or older styles
SELECT
1 AS [one],
2 [two],
3 AS 'three',
4 'four',
5 AS "five",
6 "six",
[seven] = 7,
@tcartwright
tcartwright / postman_load_cdn_js.js
Created March 12, 2025 17:23
POSTMAN: Global functions from CDN javascript file
// can be used at a collection level pre-request script to pull a js from a cdn, and expose the methods to all your requests
// can also use a script package instead of a CDN.
await (async () => {
const requestPromise = new Promise((resolve, reject) => {
pm.sendRequest("https://cdn.foo.com/foo_utils.js", (err, res) => {
if (err) {
console.error(err);
return reject(err);
}
@tcartwright
tcartwright / postman_collection_init.js
Last active March 12, 2025 19:55
POSTMAN: Set up date and lorem variables
// clear out all the current date vales and then re-add them
let vars = JSON.parse(JSON.stringify(pm.globals.values));
vars.forEach((variable) => {
let keyName = variable.key;
if (keyName.match(/^currentdate|^lorem/i)) {
pm.globals.unset(keyName);
}
});
@tcartwright
tcartwright / CleanBuildArtifacts.ps1
Last active March 3, 2025 17:57
POWERSHELL: Clean build artifacts
Clear-Host
$parentDir = $PSScriptRoot
if ($parentDir) {
Write-Host "Cleaning $parentDir" -ForegroundColor Yellow
Get-ChildItem -path $parentDir -Filter "bin" -Recurse -Directory | Remove-Item -Recurse -ErrorAction SilentlyContinue -Verbose
Get-ChildItem -path $parentDir -Filter "obj" -Recurse -Directory | Remove-Item -Recurse -ErrorAction SilentlyContinue -Verbose
} else {
@tcartwright
tcartwright / GetSystemInformation.ps1
Last active February 21, 2025 19:20
POWERSHELL: Get system information
Clear-Host
$memInfo = Get-WmiObject Win32_PhysicalMemory
$diskInfo = Get-Disk | Sort-Object DiskNumber
$driveInfo = Get-Volume | Where-Object { $_.DriveLetter } | Sort-Object DriveLetter
Write-Host 'Get-ComputerInfo' -ForegroundColor Yellow
$computerInfo = Get-ComputerInfo | Select-Object `
@{Name="DNSHostName"; Expression={$_.CsDNSHostName}},
@{Name="Domain"; Expression={$_.CsDomain}},
@tcartwright
tcartwright / TestHttpsCert.ps1
Last active February 20, 2025 14:33
POWERSHELL: Test https cert
Clear-Host
$hostName = "www.microsoft.com"
$req = [System.Net.HttpWebRequest]::Create("https://$hostName")
$req.GetResponse().Dispose()
[System.Security.Cryptography.X509Certificates.X509Certificate2]$cert = $req.ServicePoint.Certificate
#$cert | Format-List *
$props = $cert | Select-Object Subject,
@tcartwright
tcartwright / TestSPNsAndAD.ps1
Last active February 14, 2025 17:18
POWERSHELL: Test SPNs and AD connectivity
Clear-Host
Write-Host "`r`nSetspn -L `$env:COMPUTERNAME`r`n" -ForegroundColor Yellow
Setspn -L $env:COMPUTERNAME
Write-Host "`r`nSetspn -L `"`$(`$env:USERDOMAIN)\`$(`$env:USERNAME)`"`r`n" -ForegroundColor Yellow
Setspn -L "$($env:USERDOMAIN)\$($env:USERNAME)"
Write-Host "`r`nTest-ComputerSecureChannel`r`n" -ForegroundColor Yellow
Test-ComputerSecureChannel
@tcartwright
tcartwright / sort-postman-collection.bat
Created January 22, 2025 14:41
POWERSHELL: Sorts a postman collection by names of folders and requests recursively
@rem bat file to ease use of powershell script
@%~d0
@cd "%~dp0"
powershell.exe -ExecutionPolicy RemoteSigned -NoLogo -NonInteractive -NoProfile -file "%~dpn0.ps1" -Path "%~1"
@pause