Skip to content

Instantly share code, notes, and snippets.

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
View CreateLollerCoasterSql.sql
USE tempdb;
GO
IF OBJECT_ID(N'dbo.LollerCoaster', N'U') IS NOT NULL BEGIN
DROP TABLE dbo.LollerCoaster;
END;
GO
CREATE TABLE dbo.LollerCoaster (
loller_coaster_id tinyint IDENTITY(1, 1) NOT NULL,
loller_coaster_stage varchar(4000) NOT NULL
);
View Testing_WithScriptBlock.ps1
describe 'testing our function with scriptroot' {
# Get our self contained script info.
. .\Get-FunctionInfo.ps1
$fInfo = Get-FunctionInfo -Path .\Get-NameScriptBlock.ps1
# Create something we can dot-source.
$Fake = "function $($fInfo.Name) { $($fInfo.Definition) }"
$FakeFunc = [scriptblock]::Create($Fake)
. $FakeFunc
@shaneis
shaneis / Get-Name.ps1
Created Feb 22, 2019
Get-Name with extra for ScriptBlock
View Get-Name.ps1
function Get-Name {
[CmdletBinding()]
param(
[String]$Name = 'you'
)
'Hello, {0}. Script root is {1}' -f $Name, $PSScriptRoot
}
Get-Name -Name Shane
View StartingRegex.sql
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>
View RegexGroups.sql
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>
View FunkySubstring.sql
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>
View XmlStoredAsNvarchar.sql
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>
View AutomationMany.ps1
function Update-JamesStatus {
[CmdletBinding()]
param(
[Parameter(Position = 1)]
[ValidateNotNullOrEmpty()]
[String]
$SlackTitle = 'James is locked out again...',
[Parameter(Position = 2)]
[ValidateNotNullOrEmpty()]
View Automation02.ps1
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
}
View Automation01.ps1
Search-ADAccount -LockedOut |
Where-Object Name -eq 'James ReportWriter' |
Unlock-ADAccount
You can’t perform that action at this time.