Skip to content

Instantly share code, notes, and snippets.

View ashdar's full-sized avatar

dstrait ashdar

View GitHub Profile
@ashdar
ashdar / CommonlyLoggedInfo.ps1
Last active July 31, 2025 16:13
PSFramework Logging
import-module PSFramework
If ([Environment]::Is64BitProcess) {
$Message = "Running in a 64-bit PowerShell process, PowerShell {0}" -f @($PSVersionTable.PSVersion)
$Message += ' It must run in a 32-bit process because it accesses a FoxPro database.'
}
else {
$Message = 'Running in a 32-bit PowerShell process, PowerShell {0}' -f @($PSVersionTable.PSVersion)
Write-PSFMessage -Level 'Verbose' -Message $Message
}
Set-DbatoolsConfig -FullName sql.connection.trustcert -Value $true -Register
@ashdar
ashdar / Write-Simple-Log-Example.cmd
Last active June 14, 2025 16:16
Simple Write to a Log from a CMD file
@REM This will work from a .BAT or .CMD file, or from the CMD console.
@REM It's too slow to be used for regular work but it's OK for debugging and troubleshooting.
@REM It's mainly about enforcing a standard format to make it easier to parse the log file later.
PowerShell -noprofile -nologo -command "$LogLevel = 'INFO'; $Message = 'Something notable happened';$OutputTemplate = '{0},{1},{2},{3}'; Add-Content -path .\Simple.log.txt -value ($OutputTemplate -f @((Get-Date).ToString('s'), $LogLevel, $ENV:UserName, $Message) ) "
@ashdar
ashdar / Disable-BingButtonEdge.ps1
Created March 16, 2023 11:54
Use the registry to disable the Bing Button in Edge
<#
.SYNOPSIS
If you don't like the 'Bing' Button that Edge wants to display, you can use this script to turn it off.
.NOTE
Ultimately, we are just setting a registry entry. You can also do this via Active Directory policies (and a couple of other ways).
There is another, per-user rather than whole-machine, registry entry that you can set. (This is per a thread on Reddit, but I did
not bookmark that thread and I don't have time to search for it now...)
@ashdar
ashdar / settings.json
Last active May 16, 2022 22:21
My Windows Terminal Profile.json file
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions":
[
{
"command":
{
"action": "copy",
"singleLine": false
@ashdar
ashdar / SimpleArrayAndPipelineInputDemo.ps1
Created February 22, 2019 15:19
I wanted a simple way to demo how pipeline and array input works for a parameter and I thought it might be worth saving.
function foo {
[cmdletbinding()]
param (
[Parameter(Mandatory = $true,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True
)]
[string[]] $DestinationDatabase,
$TestName
)
@ashdar
ashdar / Demo-SqlCmd2WithPersistantConnection.ps1
Created August 14, 2018 18:20
Demo of dbatools\Invoke-SqlCmd2 with persistent connection, allowing begin/commit/rollback transaction
# Create the SqlConnection object
$s = New-Object System.Data.SqlClient.SqlConnection
# Build an appropriate string, using the string builder from DbaTools
$s.ConnectionString = New-DbaSqlConnectionStringBuilder -DataSource hal9000 -ApplicationName 'MyAppName' -InitialCatalog 'tempDB' -WorkstationId dstraitv7 -ColumnEncryptionSetting Disabled -IntegratedSecurity $true
# Run a query to show that we are not yet in a transaction.
# Since this is the first use of $s, this will open the connection if it isn't open already
Invoke-SqlCmd2 -Connection $s -Query "select 0 'QueryNumber', @@TRANCOUNT as CountOfTranBeforeBegin"
# Start a transaction
Invoke-SqlCmd2 -Connection $s -Query "begin tran"
# Queries 1 and 2 are just contrived nonsense
@ashdar
ashdar / Restore-DbaDatabaseSimple.Setup.sql
Last active April 7, 2018 14:33
A Pester test for testing a specific change to Restore-DbaDatabaseSimple.
/*
.SYNOPSIS
Set up backups to test Restore-DbaDatabase -RestoreTime feature when restoring a DB in Simple mode.
.NOTES
The file names here are 'Ola Hallengren'-like, but not exactly. The work for the purpose sof the test.
The file names don't match 100% to the write times either. The script had a few executions before I
had what I wanted and didn't bother changing the file names to match the times they were written.
@ashdar
ashdar / Demo-TruncationOfStringsByStoredProcedure.sql
Created October 20, 2017 21:07
A demo of how calling a procedure can silently truncate data.
/*
.PURPOSE
A demo of how calling a procedure can silently truncate data.
.AUTHOR
[email protected]
.HISTORY
2017/07/13 @dstrait Initial version
*/
<#
.SYNOPSIS
A simple example of how to use parameter sets
.DESCRIPTION
A simple example of how to use parameter sets.
Imagine that you have a function that could take a file ID or a file name.
If provided a file name, then look up the file ID and proceed as normal with that value.