Skip to content

Instantly share code, notes, and snippets.

View shaneis's full-sized avatar
🎯
The mind isn't a cup to fill but a fire to feed...my whiskey cup is empty tho...

Shane O'Neill shaneis

🎯
The mind isn't a cup to fill but a fire to feed...my whiskey cup is empty tho...
View GitHub Profile
DECLARE @XmlStoredAsNvarchar nvarchar(4000) = '
<EventContext>
<eventType>Save Test Data</eventType>
<discipline>Operations</discipline>
<documentNumber>1.2.3.4</documentNumber>
<documentVersion>1.0</documentVersion>
<sectionNumber>1.2.1.1</sectionNumber>
<sectionName>Test section: XML Test</sectionName>
<tableIdentifier>1</tableIdentifier>
<objectType>Object</objectType>
function Update-JamesStatus {
[CmdletBinding()]
param(
[Parameter(Position = 1)]
[ValidateNotNullOrEmpty()]
[String]
$SlackTitle = 'James is locked out again...',
[Parameter(Position = 2)]
[ValidateNotNullOrEmpty()]
while ((Get-Date) -lt (Get-Date '2019-01-08 17:00:00')) {
$JamesLockedAccount = Search-ADAccount -LockedOut | Where-Object Name -eq 'James ReportWriter'
if ($JamesLockedAccount) {
New-BurntToastNotification -Text 'James is locked out again.'
# Since this is a script, I'll manually clean up after myself.
Remove-Variable -Name JamesLockedAccount
}
Search-ADAccount -LockedOut |
Where-Object Name -eq 'James ReportWriter' |
Unlock-ADAccount
@shaneis
shaneis / FirstLinesOfTestsPs1.ps1
Created November 29, 2018 10:12
The first few lines of a Pester file follow this format.
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
@shaneis
shaneis / UsingForSyntax.ps1
Last active November 23, 2018 15:56
Have to use % to "go back to the start"
$String = 'SQL Server'
for ($i = 0; $i -lt $String.Length; $i++ ) {
[PSCustomObject]@{
'This Char' = $string[$i]
'Prev Char' = $string[$i -1]
'Next Char' = $string[($i +1) % $String.Length]
}
}
@shaneis
shaneis / SubstringStringSplit.ps1
Created November 12, 2018 21:21
Using substring to split string: example: basic
$String = 'SQL Server'
0..($String.Length - 1) | ForEach-Object -Process {
$String.Substring($_, 1)
}
@shaneis
shaneis / ANotEqualsA.sql
Created October 24, 2018 14:09
When N'' doesn't equal ''.
WITH Algorithms ([algorithm]) AS (
SELECT [algorithm]
FROM (VALUES ('MD2'), ('MD4'), ('MD5'), ('SHA'), ('SHA1'), ('SHA2_256'), ('SHA2_512')) AS t([algorithm])
)
SELECT [algorithm],
t.hashed_varchar,
u.hashed_nvarchar,
checked_varchar = CHECKSUM('a'),
checked_nvarchar = CHECKSUM(N'a')
FROM Algorithms
@shaneis
shaneis / ImplicitConversionUnicode.sql
Created October 24, 2018 13:18
Show there is an implicit conversion between N'' and '' types.
USE tempdb;
GO
DROP TABLE IF EXISTS dbo.NonUnicode;
DROP TABLE IF EXISTS dbo.Unicode;
CREATE TABLE dbo.NonUnicode (NU varchar(1) NOT NULL DEFAULT 'a')
CREATE TABLE dbo.Unicode (U nvarchar(1) NOT NULL DEFAULT N'a');
INSERT INTO dbo.NonUnicode (NU) DEFAULT VALUES;
INSERT INTO dbo.Unicode (U) DEFAULT VALUES;
function Get-ParameterAlias {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[Alias('Function')]
[String[]]
$Command
)
begin {