Skip to content

Instantly share code, notes, and snippets.

View indented-automation's full-sized avatar

Chris Dent indented-automation

View GitHub Profile
@indented-automation
indented-automation / Get-SqlVersionName.ps1
Last active February 8, 2017 17:00
SQL version lookup table
function Get-SqlVersionName {
param(
[Version]$Version
)
$lookup = @{
'Name' = ('Major', 'Minor', 'RTM', 'SP1', 'SP2', 'SP3', 'SP4')
'2016' = ( 13, 0, 1601, 4001 )
'2014' = ( 12, 0, 2000, 4100, 5000 )
'2012' = ( 11, 0, 2100, 3000, 5058, 6020 )
function Remove-Service {
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = 'ByName')]
param (
[Parameter(Mandatory = $true, Position = 1, ParameterSetName = 'ByName')]
[String]$Name,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'FromPipeline')]
[PSTypeName('Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_Service')]
[CimInstance]$InputObject,
function Resolve-ParameterSet {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[String]$Command,
[String[]]$ParameterName
)
try {
Option Explicit
' ContactImport.vbs
'
' Contact Import / Maintenance Script
'
' Subroutines
'
@indented-automation
indented-automation / OctoPS.json
Last active October 4, 2017 13:46
Octopus Deploy - Stream redirection
{
"Id": "ActionTemplates-62",
"Name": "OctoPS",
"Description": "A PowerShell host implementation with flexible stream redirection.\n\nThe step parameters may be used to set values for the preference variables. The ErrorActionPreference variable is set to Continue by default for all scripts executing within the host.\n\nPreference variables may be set within scripts, overriding any settings defined by the step. Additional output may be requested using the individual parameters for each stream (for example, the Verbose parameter).\n\n**Limitations and known issues**\n\n- Write-Host is not supported except in PowerShell 5 as a wrapper for Write-Information.\n- Several of the IIS commands (Stop-WebSite, Stop-WebAppPool) appear to break the output streams used by the host.",
"ActionType": "Octopus.Script",
"Version": 13,
"CommunityActionTemplateId": null,
"Properties": {
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
# Playing around with: https://blogs.msdn.microsoft.com/powershell/2007/03/03/start-demo-help-doing-demos-using-powershell/
# WIP.
function Get-DemoCommand {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[String]$Path
)
function Get-ChildProperty {
param (
$Object,
$Name
)
$current, $next = $Name -split '\.', 2
if ($next) {
Get-ChildProperty $Object.$current $next
@indented-automation
indented-automation / TaskTimeSpan.ps1
Last active January 4, 2018 09:42
Scheduled task time span converter
class TaskTimeSpan {
[Int32]$Years
[Int32]$Months
[Int32]$Days
[Int32]$Hours
[Int32]$Minutes
[Int32]$Seconds
TaskTimeSpan([String]$TimeSpanString) {
if ($TimeSpanString -match '^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?') {
function Start-Syslog {
<#
.SYNOPSIS
Start a syslog server on the current machine in a new PowerShell session.
.DESCRIPTION
Start a syslog server on the current machine in a new PowerShell session.
#>
[CmdletBinding()]
param (
@indented-automation
indented-automation / Remove-Utf8Bom.ps1
Created April 19, 2018 08:04
Removes a UTF8 BOM, if found
function Remove-Utf8Bom {
<#
.SYNOPSIS
Removes a UTF8 BOM from a file.
.DESCRIPTION
Removes a UTF8 BOM from a file if the BOM appears to be present.
The UTF8 BOM is identified by the byte sequence 0xEF 0xBB 0xBF at the beginning of the file.
.EXAMPLE
Remove-Utf8Bom -Path c:\file.txt