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
@shaneis
shaneis / paramsection.ps1
Last active October 3, 2018 13:21
How to set parameter aliases
<#
function name
comment based help
etc
etc
#>
param(
[parameter(position = 1,
parametersetname = 'id')]
[string]$Identity,
@shaneis
shaneis / AliasInAFunction.ps1
Created October 3, 2018 13:14
Where to put an Alias attribute in a function
function Get-VideoPlayBackTime {
<#
comment based help
#>
[Alias('video')] # <-- This guy!
[CmdletBinding()]
[OutputType([PSCustomObject])]
param (
# Minutes of the video only
[Parameter(Position = 0)]
function ConvertTo-Parameters {
$Path = (Read-Host -Prompt 'Enter the location of the folder')
$Number = (Read-Host -Prompt 'Enter a number from 1 to 10')
$Set = (Read-Host -Prompt 'Choose a set of Set1, Set2, or Set3')
Test-Parameters -Path $Path -Number $Number -Set $Set
}
function Test-DefaultParameters {
[cmdletbinding()]
param(
[parameter(Position = 0)]
[ValidateScript({ Test-Path -Path $_ })]
[Alias('PSPath')]
[string]
$Path = (Read-Host -Prompt 'Enter the location of the folder'),
[parameter(Position = 1)]
@shaneis
shaneis / Test-ParametersAndPrompts.ps1
Last active September 21, 2018 10:25
Added stop with error
function Test-ParametersAndPrompts {
[cmdletbinding()]
param(
[parameter(Position = 0, HelpMessage = 'Enter the location of the folder.')]
[ValidateScript({ Test-Path -Path $_ })]
[Alias('PSPath')]
[string]
$Path,
[parameter(Position = 1, HelpMessage = 'Enter a number from 1 to 10.')]
function Test-Parameters {
[cmdletbinding()]
param(
[parameter(Mandatory, Position = 0, HelpMessage = 'Enter the location of the folder.')]
[ValidateScript({ Test-Path -Path $_ })]
[Alias('PSPath')]
[string]
$Path,
[parameter(Mandatory, Position = 1, HelpMessage = 'Enter a number from 1 to 10.')]
@shaneis
shaneis / Test-Prompts.ps1
Created September 20, 2018 20:56
Prompts only
function Test-Prompts {
do {
[string]$Path = Read-Host -Prompt 'Enter the location of the folder.'
} until (Test-Path -Path $Path)
do {
[int]$Number = Read-Host -Prompt 'Enter a number from 1 to 10.'
} until ($Number -ge 1 -and $Number -le 10)
function Test-Prompts {
do {
[string]$Path = Read-Host -Prompt 'Enter the location of the folder.'
} until (Test-Path -Path $Path)
do {
[int]$Number = Read-Host -Prompt 'Enter a number from 1 to 10.'
} until ($Number -ge 1 -and $Number -le 10)
@shaneis
shaneis / CreateDatabaseTrigger.sql
Last active September 9, 2018 20:08
Trigger to capture database creation and command used.
-- region Server Trigger
IF EXISTS (SELECT * FROM sys.server_triggers WHERE name = N'NewDatabase') DROP TRIGGER NewDatabase ON ALL SERVER;
GO
CREATE TRIGGER NewDatabase
ON ALL SERVER
FOR CREATE_DATABASE
AS
SELECT EVENTDATA().value('(/EVENT_INSTANCE/ServerName)[1]', 'nvarchar(256)') AS ServerName,
EVENTDATA().value('(/EVENT_INSTANCE/DatabaseName)[1]', 'nvarchar(128)') AS DatabaseName,
EVENTDATA().value('(/EVENT_INSTANCE/PostTime)[1]', 'datetime') AS CreateTime,
@shaneis
shaneis / Test-EditedConfirm.ps1
Last active August 29, 2018 07:56
Edit all the things!
#region Test-EditedConfirm
function Test-EditedConfirm {
[CmdletBinding(SupportsShouldProcess,
ConfirmImpact = 'High')]
param(
[int[]]$Numbers
)
process {
foreach ($num in $Numbers) {
if ($PSCmdlet.ShouldProcess("Guess what this does? [$num]",