├── Chef ├── berkshelf_config_example.json └── knife_example.rb ├── Fun └── Get-Ascii.ps1 ├── General ├── Export-SystemAccountCredential.ps1 └── Start-ProcessWithCapture.ps1 ├── Hubot └── Get-ServiceHubot.ps1 ├── LICENSE ├── PowerShellProfile └── Microsoft.PowerShell_profile.ps1 ├── README.md └── VictorOps └── Send-VictorOpsEvent.ps1 /Chef/berkshelf_config_example.json: -------------------------------------------------------------------------------- 1 | { 2 | "chef":{ 3 | "chef_server_url":"https://your.chef.server.com:443/organizations/your_org", 4 | "validation_client_name":"chef-validator", 5 | "validation_key_path":"~/.chef/chef-validator.pem", 6 | "client_key":"~/.chef/your_user.pem", 7 | "node_name":"your_user" 8 | }, 9 | "cookbook":{ 10 | "copyright":"Your Company", 11 | "email":"your@email.com", 12 | "license":"reserved" 13 | }, 14 | "allowed_licenses":[], 15 | "raise_license_exception":false, 16 | "vagrant":{ 17 | "vm":{ 18 | "box":"kensykora/windows_2012_r2_standard", 19 | "forward_port":{}, 20 | "provision":"chef_solo" 21 | } 22 | }, 23 | "ssl":{ 24 | "verify":true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chef/knife_example.rb: -------------------------------------------------------------------------------- 1 | log_level :info 2 | log_location STDOUT 3 | node_name 'your_user' 4 | client_key 'your_user.pem' 5 | validation_client_name 'chef-validator' 6 | validation_key '~/.chef/chef-validator.pem' 7 | chef_server_url 'https://your.chef.server.com:443/organizations/your_org' 8 | chef_server_root 'https://your.chef.server.com:443' 9 | syntax_check_cache_path 'syntax_check_cache' 10 | knife[:editor] = 'C:/Windows/System32/notepad.exe' 11 | current_dir = File.dirname(__FILE__) 12 | cookbook_path [ 13 | 'D:/ProjectsGit/your-chef-repo/cookbooks' 14 | ] 15 | knife[:vault_mode] = 'client' 16 | -------------------------------------------------------------------------------- /Fun/Get-Ascii.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Displays Ascii for different reactions and copies it to clipboard. 4 | .DESCRIPTION 5 | Displays Ascii for different reactions and copies it to clipboard. 6 | .EXAMPLE 7 | Get-Ascii -Name Shrug 8 | 9 | Displays a shurg and copies it to clipboard. 10 | #> 11 | function Get-Ascii { 12 | [cmdletbinding()] 13 | 14 | Param 15 | ( 16 | # Name of the Ascii 17 | [Parameter(Mandatory=$true)] 18 | [ValidateSet( 19 | 'Shrug', 20 | 'Disapproval', 21 | 'TableFlip', 22 | 'TableBack', 23 | 'TableFlip2', 24 | 'TableBack2', 25 | 'TableFlip3', 26 | 'Denko', 27 | 'BlowKiss', 28 | 'Lenny', 29 | 'Angry', 30 | 'DontKnow')] 31 | [string] 32 | $Name 33 | ) 34 | 35 | $OutputEncoding = [System.Text.Encoding]::unicode 36 | 37 | # Function to write ascii to screen as well as clipboard it 38 | function Write-Ascii 39 | { 40 | [CmdletBinding()] 41 | Param 42 | ( 43 | # Ascii Data 44 | [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] 45 | [string] 46 | $Ascii 47 | ) 48 | 49 | # Clips it without the newline 50 | Add-Type -Assembly PresentationCore 51 | $clipText = ($Ascii).ToString() | Out-String -Stream 52 | [Windows.Clipboard]::SetText($clipText) 53 | 54 | Write-Output $clipText 55 | } 56 | 57 | Switch ($Name) 58 | { 59 | 'Shrug' { [char[]]@(175,92,95,40,12484,41,95,47,175) -join '' | Write-Ascii} 60 | 'Disapproval' { [char[]]@(3232,95,3232) -join '' | Write-Ascii } 61 | 'TableFlip' { [char[]]@(40,9583,176,9633,176,65289,9583,65077,32,9531,9473,9531,41) -join '' | Write-Ascii } 62 | 'TableBack' { [char[]]@(9516,9472,9472,9516,32,175,92,95,40,12484,41) -join '' | Write-Ascii } 63 | 'TableFlip2' { [char[]]@(9531,9473,9531,32,65077,12541,40,96,1044,180,41,65417,65077,32,9531,9473,9531) -join '' | Write-Ascii } 64 | 'TableBack2' { [char[]]@(9516,9472,9516,12494,40,32,186,32,95,32,186,12494,41) -join '' | Write-Ascii } 65 | 'TableFlip3' { [char[]]@(40,12494,3232,30410,3232,41,12494,24417,9531,9473,9531) -join '' | Write-Ascii } 66 | 'Denko' { [char[]]@(40,180,65381,969,65381,96,41) -join '' | Write-Ascii } 67 | 'BlowKiss' { [char[]]@(40,42,94,51,94,41,47,126,9734) -join '' | Write-Ascii} 68 | 'Lenny' { [char[]]@(40,32,865,176,32,860,662,32,865,176,41) -join '' | Write-Ascii } 69 | 'Angry' { [char[]]@(40,65283,65439,1044,65439,41) -join '' | Write-Ascii } 70 | 'DontKnow' { [char[]]@(9488,40,39,65374,39,65307,41,9484) -join '' | Write-Ascii } 71 | } 72 | } -------------------------------------------------------------------------------- /General/Export-SystemAccountCredential.ps1: -------------------------------------------------------------------------------- 1 | #Requires -RunAsAdministrator 2 | 3 | <# 4 | .Synopsis 5 | Generates a Credential .xml file to be used with Import-Clixml 6 | .DESCRIPTION 7 | Creates a credential .xml file exported from Export-Clixml from the SYSTEM account. This is useful when running scripts or services under the SYSTEM account that requires credentials. 8 | .EXAMPLE 9 | $cred = Get-Credential 10 | Export-SystemAccountCredential -Credential $cred -Path 'C:\mycreds' -Verbose 11 | #> 12 | function Export-SystemAccountCredential 13 | { 14 | [CmdletBinding()] 15 | Param 16 | ( 17 | # Credential to export under the SYSTEM account. 18 | [Parameter(Mandatory=$true)] 19 | [PSCredential] 20 | $Credential, 21 | 22 | # Path to store export the credential to 23 | [string] 24 | $Path 25 | ) 26 | 27 | if (!(Test-Path -Path $Path)) 28 | { 29 | New-Item -Path $Path -Type Directory -Force 30 | } 31 | 32 | $schTaskName = 'CreateCredential' 33 | $scriptName = "$($schTaskName).ps1" 34 | 35 | # define the scheduled task 36 | [scriptblock]$schTaskScript = { 37 | # take the params passed to the script 38 | param ( 39 | $Username, 40 | $Password, 41 | $Path 42 | ) 43 | $Username = "\$Username" 44 | $npipeClient = new-object System.IO.Pipes.NamedPipeClientStream($env:ComputerName, 'task', [System.IO.Pipes.PipeDirection]::Out) 45 | $npipeclient.connect() 46 | $pipeWriter = new-object System.IO.StreamWriter($npipeClient) 47 | $pipeWriter.AutoFlush = $true 48 | 49 | # convert to creds block 50 | $pw = $Password | ConvertTo-SecureString -AsPlainText -Force 51 | $credential = New-Object System.Management.Automation.PSCredential($Username,$pw) 52 | 53 | $pipewriter.writeline("Generating Credential for $($Credential.Username)") 54 | $Credential | Export-Clixml -Path "$($Path)\$($Credential.Username)_credential.xml" 55 | 56 | $pipewriter.writeline("SCHEDULED_TASK_DONE: $LastExitCode") 57 | $pipewriter.dispose() 58 | $npipeclient.dispose() 59 | }.GetNewClosure() 60 | 61 | Write-Verbose "Creating Script File" 62 | $scriptPath = Join-Path $env:TEMP $scriptName 63 | Set-Content -Path $scriptPath -Value $schTaskScript -Force 64 | 65 | Write-Verbose "Creating Scheduled Task" 66 | # create scheduled task with params that the script will need 67 | Start-Process -FilePath 'schtasks' -ArgumentList "/create /tn $($schTaskName) /ru SYSTEM /sc once /st 00:00 /sd 01/01/2005 /f /tr ""powershell -executionpolicy unrestricted -File '$($scriptPath)' $($Credential.Username) $($Credential.GetNetworkCredential().Password) $Path""" -Wait -NoNewWindow 68 | 69 | Start-Sleep -Seconds 5 70 | 71 | Write-Verbose "Running Scheduled Task" 72 | try 73 | { 74 | $npipeServer = new-object System.IO.Pipes.NamedPipeServerStream('task', [System.IO.Pipes.PipeDirection]::In) 75 | $pipeReader = new-object System.IO.StreamReader($npipeServer) 76 | Start-Process -FilePath 'schtasks' -ArgumentList "/run /tn ""$($schTaskName)""" 77 | $npipeserver.waitforconnection() 78 | $host.ui.writeline('Connected to the scheduled task.') 79 | while ($npipeserver.IsConnected) 80 | { 81 | $output = $pipereader.ReadLine() 82 | if ($output -like 'SCHEDULED_TASK_DONE:*') 83 | { 84 | $exit_code = ($output -replace 'SCHEDULED_TASK_DONE:').trim() 85 | } 86 | else 87 | { 88 | $host.ui.WriteLine($output) 89 | } 90 | } 91 | } 92 | catch 93 | { 94 | if ($_.Exception.Message) 95 | { 96 | Write-Error $_.Exception.Message 97 | } 98 | 99 | if ($_.Exception.ItemName) 100 | { 101 | Write-Error $_.Exception.ItemName 102 | } 103 | 104 | if ($_.CategoryInfo.Reason) 105 | { 106 | Write-Error $_.CategoryInfo.Reason 107 | } 108 | 109 | if ($_.CategoryInfo.Category) 110 | { 111 | Write-Error $_.CategoryInfo.Category.ToString() 112 | } 113 | 114 | if ($_.CategoryInfo.Activity) 115 | { 116 | Write-Error $_.CategoryInfo.Activity 117 | } 118 | } 119 | finally 120 | { 121 | $pipereader.dispose() 122 | $npipeserver.dispose() 123 | 124 | Write-Verbose "Removing Scheduled Task" 125 | Start-Process -FilePath 'schtasks' -ArgumentList "/Delete /TN $($schTaskName) /F" 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /General/Start-ProcessWithCapture.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Allows running processes and capturing output. 4 | .DESCRIPTION 5 | Allows running processes and capturing output. 6 | .EXAMPLE 7 | Start-ProcessWithCapture -FilePath 'git' -ArgumentList 'pull' -WorkingDirectory $Path -ErrorAction Stop 8 | #> 9 | function Start-ProcessWithCapture 10 | { 11 | [CmdletBinding()] 12 | Param 13 | ( 14 | # File Path of the Process to Execute 15 | [Parameter(Mandatory=$true)] 16 | [string] 17 | $FilePath, 18 | 19 | # Argument List for Process 20 | [Parameter(Mandatory=$true)] 21 | [string] 22 | $ArgumentList, 23 | 24 | # Argument List for Process 25 | [Parameter(Mandatory=$false)] 26 | [string] 27 | $WorkingDirectory 28 | ) 29 | 30 | $pinfo = New-Object System.Diagnostics.ProcessStartInfo 31 | 32 | if ($PSBoundParameters.ContainsKey('WorkingDirectory')) 33 | { 34 | $pinfo.WorkingDirectory = $WorkingDirectory 35 | } 36 | 37 | $pinfo.FileName = $FilePath 38 | $pinfo.RedirectStandardError = $true 39 | $pinfo.RedirectStandardOutput = $true 40 | $pinfo.UseShellExecute = $false 41 | $pinfo.Arguments = $ArgumentList 42 | $p = New-Object System.Diagnostics.Process 43 | $p.StartInfo = $pinfo 44 | $p.Start() | Out-Null 45 | $p.WaitForExit() 46 | $stdout = $p.StandardOutput.ReadToEnd() 47 | $stderr = $p.StandardError.ReadToEnd() 48 | 49 | $output = @{} 50 | $output.stdout = $stdout 51 | $output.stderr = $stderr 52 | $output.exitcode = $p.ExitCode 53 | 54 | return $output 55 | } 56 | -------------------------------------------------------------------------------- /Hubot/Get-ServiceHubot.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets service status for Hubot Script. 4 | .DESCRIPTION 5 | Gets service status for Hubot Script. 6 | .EXAMPLE 7 | Get-ServiceHubot -Name dhcp 8 | #> 9 | function Get-ServiceHubot 10 | { 11 | [CmdletBinding()] 12 | Param 13 | ( 14 | # Name of the Service 15 | [Parameter(Mandatory=$true)] 16 | $Name 17 | ) 18 | 19 | $result = @{} 20 | 21 | try 22 | { 23 | $service = Get-Service -Name $Name -ErrorAction Stop 24 | $result.output = "Service $($service.Name) (*$($service.DisplayName)*) is currently ``$($service.Status.ToString())``." 25 | $result.success = $true 26 | } 27 | catch 28 | { 29 | $result.output = "Service $($Name) does not exist on this server." 30 | $result.success = $false 31 | } 32 | 33 | return $result | ConvertTo-Json 34 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Matthew Hodgkins 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /PowerShellProfile/Microsoft.PowerShell_profile.ps1: -------------------------------------------------------------------------------- 1 | ########################## 2 | # Import PoshGit 3 | ########################## 4 | 5 | Import-Module -Name Posh-Git 6 | 7 | ########################## 8 | # Colourize Prompt 9 | ########################## 10 | 11 | Import-Module Get-ChildItemColor 12 | Set-Alias l Get-ChildItemColor -option AllScope 13 | Set-Alias ls Get-ChildItemColor -option AllScope 14 | 15 | ########################## 16 | # Open Git Path 17 | ########################## 18 | 19 | if (Test-Path -Path 'C:\ProjectsGit') 20 | { 21 | Set-Location -Path "C:\ProjectsGit" 22 | } 23 | 24 | <# 25 | .Synopsis 26 | Adds an Environment Variable to the system 27 | .EXAMPLE 28 | Add-EnvironmentVariable -Variable "GOPATH" -Value F:\ProjectsGit\gotesting\ 29 | .EXAMPLE 30 | Add-EnvironmentVariable -Variable "GOROOT" -Value 'C:\tools\go' 31 | #> 32 | function Add-EnvironmentVariable 33 | { 34 | [CmdletBinding()] 35 | Param 36 | ( 37 | # The environment variable to add 38 | [Parameter(Mandatory=$true)] 39 | [string] 40 | $Variable, 41 | 42 | # The value of the environment variable 43 | [Parameter(Mandatory=$true)] 44 | [string] 45 | $Value 46 | ) 47 | 48 | try 49 | { 50 | [Environment]::SetEnvironmentVariable($Variable, $Value, [EnvironmentVariableTarget]::User) 51 | Write-Output "$($Variable) with value $($Value) added to environment variables" 52 | } 53 | catch 54 | { 55 | Write-Error $_ 56 | } 57 | } 58 | 59 | ########################## 60 | # Reload Path Variables 61 | ########################## 62 | 63 | function Import-PathVariable 64 | { 65 | # Reload Path Variable 66 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 67 | } 68 | 69 | Import-PathVariable 70 | 71 | function Show-PathVariable 72 | { 73 | $env:Path -split ';' 74 | } 75 | 76 | <# 77 | .Synopsis 78 | Adds a Path Variable to the system 79 | .EXAMPLE 80 | Example of how to use this cmdlet 81 | .EXAMPLE 82 | Another example of how to use this cmdlet 83 | #> 84 | function Add-PathVariable 85 | { 86 | [CmdletBinding()] 87 | Param 88 | ( 89 | # Param1 help description 90 | [Parameter(Mandatory=$true)] 91 | [ValidateScript({ 92 | if(Test-Path -Path $_ -ErrorAction SilentlyContinue) 93 | { 94 | return $true 95 | } 96 | else 97 | { 98 | throw "$($_) does not exist." 99 | } 100 | })] 101 | [string] 102 | $Path 103 | ) 104 | 105 | # Refresh Path Variables 106 | Import-PathVariable 107 | 108 | # Replace incorrect facing slashes 109 | $Path = $Path -replace '/','\' 110 | Write-Verbose "Path being used is $($Path)." 111 | 112 | # Check Path Variable First 113 | $arrayOfPaths = $env:Path -split ';' 114 | 115 | if ($arrayOfPaths -contains $Path) 116 | { 117 | Write-Output "Path $($Path) already exists in the path environment variable" 118 | } 119 | else 120 | { 121 | try 122 | { 123 | [Environment]::SetEnvironmentVariable("Path", $env:Path + ";$($Path)", [EnvironmentVariableTarget]::User) 124 | Write-Output "Path $($Path) added to the path environment variable" 125 | # Refresh Path Variables 126 | Import-PathVariable 127 | } 128 | catch 129 | { 130 | Write-Error $_ 131 | } 132 | } 133 | } 134 | 135 | ########################## 136 | # Style Prompt 137 | ########################## 138 | 139 | function prompt 140 | { 141 | Set-StrictMode -Off 142 | 143 | $history = Get-History 144 | $nextHistoryId = $history.Count + 1 145 | Write-Host "[" -ForegroundColor DarkGray -NoNewline 146 | Write-Host "$nextHistoryId" -ForegroundColor Red -NoNewline 147 | Write-Host "|" -ForegroundColor DarkGray -NoNewline 148 | 149 | Write-Host "$((Get-Date).ToShortTimeString())" -ForegroundColor Yellow -NoNewline 150 | 151 | if ($history) { 152 | $timing = $history[-1].EndExecutionTime - $history[-1].StartExecutionTime 153 | Write-Host "|" -ForegroundColor DarkGray -NoNewline 154 | 155 | $color = "Green" 156 | if ($timing.TotalSeconds -gt 1) { 157 | $color = "Red" 158 | } 159 | 160 | Write-Host "+" -ForegroundColor $color -NoNewline 161 | if ($timing.Hours) { Write-Host "$(($timing).Hours)h " -ForegroundColor $color -NoNewline } 162 | if ($timing.Minutes) { Write-Host "$(($timing).Minutes)m " -ForegroundColor $color -NoNewline } 163 | if ($timing.Seconds) { Write-Host "$(($timing).Seconds)s " -ForegroundColor $color -NoNewline } 164 | Write-Host "$(($timing).Milliseconds)ms" -ForegroundColor $color -NoNewline 165 | } 166 | 167 | Write-Host "] " -ForegroundColor DarkGray -NoNewline 168 | 169 | Write-Host "[" -ForegroundColor DarkGray -NoNewline 170 | 171 | [string]$path = $Pwd.Path 172 | 173 | if ($path -like "c:\users\$env:username*") { 174 | $path = "~home" + $path.Substring("c:\users\$env:username".Length) 175 | } 176 | 177 | $chunks = $path -split '\\' 178 | 179 | $short = $false 180 | if ($Pwd.Path.Length -gt 30 -and $chunks.Length -gt 2) { 181 | $chunks = $chunks | select -Last 2 182 | $short = $true 183 | } 184 | 185 | if ($short) { 186 | Write-Host "...\" -ForegroundColor DarkGray -NoNewline 187 | } 188 | 189 | $chunks | % { $i = 0 } { 190 | $i++ 191 | $color = "Yellow" 192 | 193 | if ($_ -like "~home") { $color = "Green" } 194 | Write-Host "$_" -ForegroundColor $color -NoNewline 195 | 196 | if ($i -le $chunks.Count-1) { 197 | Write-Host "\" -ForegroundColor DarkGray -NoNewline 198 | } 199 | } 200 | 201 | Write-Host "]" -ForegroundColor DarkGray -NoNewline 202 | 203 | 204 | $g = Get-GitStatus 205 | 206 | if ($g) { 207 | Write-Host " [" -ForegroundColor DarkGray -NoNewline 208 | 209 | $branch = $g.Branch.Split("...") | select -first 1 210 | Write-Host $branch -ForegroundColor Red -NoNewline 211 | 212 | $add = $g.Working.Added.Count 213 | $cha = $g.Working.Modified.Count 214 | $del = $g.Working.Deleted.Count 215 | $ahead = $g.AheadBy 216 | $behind = $g.BehindBy 217 | 218 | if ($add) { 219 | Write-Host "|" -ForegroundColor DarkGray -NoNewline 220 | Write-Host "+$add" -ForegroundColor Yellow -NoNewline 221 | } 222 | 223 | if ($rem) { 224 | Write-Host "|" -ForegroundColor DarkGray -NoNewline 225 | Write-Host "-$rem" -ForegroundColor Yellow -NoNewline 226 | } 227 | 228 | if ($cha) { 229 | Write-Host "|" -ForegroundColor DarkGray -NoNewline 230 | Write-Host "~$cha" -ForegroundColor Yellow -NoNewline 231 | } 232 | 233 | if (!$g.Working) { 234 | Write-Host "|" -ForegroundColor DarkGray -NoNewline 235 | Write-Host "clean" -ForegroundColor Green -NoNewline 236 | } 237 | 238 | if ($ahead) { 239 | Write-Host "|" -ForegroundColor DarkGray -NoNewline 240 | Write-Host "▲$ahead" -ForegroundColor Green -NoNewline 241 | } 242 | 243 | if ($behind) { 244 | Write-Host "|" -ForegroundColor DarkGray -NoNewline 245 | Write-Host "▼$behind" -ForegroundColor Red -NoNewline 246 | } 247 | 248 | Write-Host "]" -ForegroundColor DarkGray -NoNewline 249 | } 250 | Write-Host "`n>" -ForegroundColor DarkGray -NoNewline 251 | return " " 252 | } 253 | 254 | ########################## 255 | # Run pester tests in a background job 256 | ########################## 257 | 258 | function Invoke-PesterJob 259 | { 260 | [CmdletBinding(DefaultParameterSetName = 'LegacyOutputXml')] 261 | param( 262 | [Parameter(Position=0,Mandatory=0)] 263 | [Alias('Path', 'relative_path')] 264 | [object[]]$Script = '.', 265 | 266 | [Parameter(Position=1,Mandatory=0)] 267 | [Alias("Name")] 268 | [string[]]$TestName, 269 | 270 | [Parameter(Position=2,Mandatory=0)] 271 | [switch]$EnableExit, 272 | 273 | [Parameter(Position=3,Mandatory=0, ParameterSetName = 'LegacyOutputXml')] 274 | [string]$OutputXml, 275 | 276 | [Parameter(Position=4,Mandatory=0)] 277 | [Alias('Tags')] 278 | [string[]]$Tag, 279 | 280 | [string[]]$ExcludeTag, 281 | 282 | [switch]$PassThru, 283 | 284 | [object[]] $CodeCoverage = @(), 285 | 286 | [Switch]$Strict, 287 | 288 | [Parameter(Mandatory = $true, ParameterSetName = 'NewOutputSet')] 289 | [string] $OutputFile, 290 | 291 | [Parameter(ParameterSetName = 'NewOutputSet')] 292 | [ValidateSet('LegacyNUnitXml', 'NUnitXml')] 293 | [string] $OutputFormat = 'NUnitXml', 294 | 295 | [Switch]$Quiet, 296 | 297 | [object]$PesterOption 298 | ) 299 | 300 | $params = $PSBoundParameters 301 | 302 | Start-Job -ScriptBlock { Set-Location $using:pwd; Invoke-Pester @using:params } | 303 | Receive-Job -Wait -AutoRemoveJob 304 | } 305 | 306 | function ConvertFrom-PesterOutputObject { 307 | param ( 308 | [parameter(ValueFromPipeline=$true)] 309 | [object] 310 | $InputObject 311 | ) 312 | begin { 313 | $PesterModule = Import-Module Pester -Passthru 314 | } 315 | process { 316 | $DescribeGroup = $InputObject.testresult | Group-Object Describe 317 | foreach ($DescribeBlock in $DescribeGroup) { 318 | $PesterModule.Invoke({Write-Screen $args[0]}, "Describing $($DescribeBlock.Name)") 319 | $ContextGroup = $DescribeBlock.group | Group-Object Context 320 | foreach ($ContextBlock in $ContextGroup) { 321 | $PesterModule.Invoke({Write-Screen $args[0]}, "`tContext $($subheader.name)") 322 | foreach ($TestResult in $ContextBlock.group) { 323 | $PesterModule.Invoke({Write-PesterResult $args[0]}, $TestResult) 324 | } 325 | } 326 | } 327 | $PesterModule.Invoke({Write-PesterReport $args[0]}, $InputObject) 328 | } 329 | } 330 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MattHodgePowerShell 2 | Various PowerShell functions and scripts 3 | -------------------------------------------------------------------------------- /VictorOps/Send-VictorOpsEvent.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | Written by Matthew Hodgkins. 4 | .VERSION 5 | 1.0.0 (11/19/2015) 6 | .Synopsis 7 | Sends VictorOps events using the VictorOps REST API. 8 | .DESCRIPTION 9 | Sends VictorOps events using the VictorOps REST API. More details on the API http://victorops.force.com/knowledgebase/articles/Integration/Alert-Ingestion-API-Documentation/ 10 | .EXAMPLE 11 | $sendEventSplat = @{ 12 | ApiKey = '1111111-11111-111-111-111111' 13 | message_type = 'CRITICAL' 14 | RoutingKey = 'matt_test' 15 | entity_id = 'mattlaptop\some_service' 16 | monitoring_tool = 'powershell' 17 | state_message = 'testing a failed trigger' 18 | } 19 | 20 | Send-VictorOpsEvent @sendEventSplat 21 | 22 | Send a VictorOps event using a splat. 23 | #> 24 | function Send-VictorOpsEvent 25 | { 26 | [CmdletBinding()] 27 | Param 28 | ( 29 | # API Key for your VictorOps Account 30 | [Parameter(Mandatory=$true)] 31 | $ApiKey, 32 | 33 | # The Routing Key to use for sending the event 34 | [Parameter(Mandatory=$true)] 35 | $RoutingKey, 36 | 37 | # The API URI (excluding the API and Routing keys) - Default is 'https://alert.victorops.com/integrations/generic/20131114/alert' 38 | [Parameter(Mandatory=$false)] 39 | $BaseURI = 'https://alert.victorops.com/integrations/generic/20131114/alert', 40 | 41 | # The type of message to send VictorOps 42 | [Parameter(Mandatory=$true)] 43 | [ValidateSet('INFO', 'ACKNOWLEDGEMENT', 'CRITICAL', 'RECOVERY')] 44 | $message_type, 45 | 46 | # The name of alerting entity. If not provided, a random name will be assigned. 47 | [Parameter(Mandatory=$false)] 48 | [string] 49 | $entity_id, 50 | 51 | # The name of the monitoring system software (eg. nagios, icinga, sensu, etc.) 52 | [Parameter(Mandatory=$false)] 53 | [string] 54 | $monitoring_tool, 55 | 56 | # Any additional status information from the alert item. 57 | [Parameter(Mandatory=$false)] 58 | [string] 59 | $state_message, 60 | 61 | # Used within VictorOps to display a human-readable name for the entity. 62 | [Parameter(Mandatory=$false)] 63 | [string] 64 | $entity_display_name, 65 | 66 | # A hash table of any other key/value pairs you want sent to VictorOps 67 | [Parameter(Mandatory=$false)] 68 | [System.Collections.Hashtable] 69 | $KeyValueHash, 70 | 71 | # Enable Logging 72 | [Parameter(Mandatory=$false)] 73 | [string] 74 | $LogPath 75 | ) 76 | 77 | $fullURI = "$($BaseURI)/$($ApiKey)/$($RoutingKey)" 78 | Write-Verbose "Full API URI Being Used: $($fullURI)" 79 | 80 | $body = @{ 81 | message_type = $message_type 82 | } 83 | 84 | if ($PSBoundParameters.ContainsKey('entity_id')) { 85 | $body.entity_id = $entity_id 86 | } 87 | 88 | if ($PSBoundParameters.ContainsKey('monitoring_tool')) { 89 | $body.monitoring_tool = $monitoring_tool 90 | } 91 | 92 | if ($PSBoundParameters.ContainsKey('state_message')) { 93 | $body.state_message = $state_message 94 | } 95 | 96 | if ($PSBoundParameters.ContainsKey('entity_display_name')) { 97 | $body.entity_display_name = $entity_display_name 98 | } 99 | 100 | if ($PSBoundParameters.ContainsKey('KeyValueHash')) { 101 | $body += $KeyValueHash 102 | } 103 | if ($PSBoundParameters.ContainsKey('LogPath')) { 104 | $Logging = $true 105 | } 106 | 107 | $body_json = $body | ConvertTo-Json 108 | Write-Verbose $body_json 109 | 110 | if ($Logging) 111 | { 112 | New-Item -Path $LogPath -ItemType Directory -Force -ErrorAction SilentlyContinue 113 | $guid = [guid]::NewGuid().Guid 114 | 115 | # Create Json 116 | Set-Content -Path "$($LogPath)\$($guid)_json.txt" -Value $body_json 117 | } 118 | 119 | Invoke-WebRequest -UseBasicParsing -Uri $fullURI -Body $body_json -method Post -ContentType "application/json" 120 | } 121 | --------------------------------------------------------------------------------