Skip to content

Instantly share code, notes, and snippets.

View Jaykul's full-sized avatar
😀
Learning

Joel Bennett Jaykul

😀
Learning
View GitHub Profile
@Jaykul
Jaykul / Awful.ps1
Created March 1, 2017 01:17
The terrigly things you do for ISE
gci | ft Mode, LastWriteTime, Length, Name -Auto |
Out-String -stream | % {
if($_ -match '^d') {
Write-Host ($_ -replace "^\S+\s+") -foreground "Red" -BackgroundColor Black
} elseif($_ -match '^-') {
Write-Host ($_ -replace "^\S+\s+") -Foreground "Blue" -BackgroundColor Black
} else {
Write-Host ($_ -replace "^\S+\s+") -Foreground "Green" -BackgroundColor Black
}
}
@Jaykul
Jaykul / Error.md
Last active March 22, 2017 04:42
Azure AD + PowerShell Remoting
Invoke-Command localhost { "Hello" }
[localhost] Connecting to remote server localhost failed with the following error message : WinRM cannot process the request. The following error with errorcode 0x8009030e occurred while using Negotiate
authentication: A specified logon session does not exist. It may already have been terminated.
 Possible causes are:
  -The user name or password specified are invalid.
  -Kerberos is used when no authentication method and no user name are specified.
  -Kerberos accepts domain user names, but not local user names.
@Jaykul
Jaykul / Example.xml
Last active June 21, 2017 21:13
Writing a test for properties of an object
<ExtensionData>
<Extension Type="Policy">
<RuleCollection Type="Appx" />
<RuleCollection Type="Dll" />
<RuleCollection Type="Exe" />
<RuleCollection Type="Msi">
<FilePublisherRule Id="cb7a6322-9aeb-461a-89e3-54b34456617c" Name="Allow only signed installers" Description="" UserOrGroupSid="S-1-1-0" Action="Allow">
<Conditions>
<FilePublisher PublisherName="*" ProductName="*" BinaryName="*">
<BinaryVersionRange />
@Jaykul
Jaykul / Hide-FromDebugger.ps1
Created July 29, 2017 23:01
Have you ever wished you could hide a few commands from the PowerShell step-through?
<#
.SYNOPSIS
Wrap commands with DebuggerNonUserCode attribute to prevent the PowerShell debugger stepping into them
.DESCRIPTION
Generates proxy functions that wrap the original commands, and put an attribute on the proxy to prevent the debugger stopping.
.EXAMPLE
Get-Command -Module Pester | Hide-FromDebugger
Hides all pester functions from the debugger, so you can debug in your code without stepping into Pester functions.
#>
@Jaykul
Jaykul / New-LoggingCommand.ps1
Created July 27, 2017 23:44
Something I need to add to the Information Module
[CmdletBinding()]
param(
[System.Management.Automation.CommandMetadata]
$Command
)
begin {
$ProxyFactory = [System.Management.Automation.ProxyCommand]
<#
class TraceInformation {
[String]$Message
$url = "https://octopus.jaykul.com"
# Create our App registration
$Application = @{
DisplayName = $DisplayName
IdentifierUris = $Url
Homepage = "$url/app"
ReplyUrls = "$url", "$url/app/users/authenticatedToken/AzureAD"
LogoutUrl = "$url/app#/users/sign-out"
AppRoles = @(
@Jaykul
Jaykul / OctopusDeploy.psm1
Created May 11, 2017 18:43
I needed to do some octopus stuff, and didn't like any of the code I found ...
$OctopusInstallPath = "C:\Program Files\Octopus Deploy\Octopus";
Add-Type -Path "$OctopusInstallPath\Octopus.Client.dll"
function Set-OctopusEndpoint {
<#
.Synopsis
Sets the connection endpoint for an Octopus deploy instance
.DESCRIPTION
Registers the octopus endpoint with the given information.
@Jaykul
Jaykul / ErrorHandlingFunction.ps1
Last active March 7, 2018 19:18
Minimal effort at error logging
function Verb-Noun {
[CmdletBinding()]
param()
Push-Location -Stack Verb-Noun
# BOILER PLATE ERROR HANDLING
trap { # Standard practice in every script
$ex = $_
do {
$Stack = if($ex.ScriptStackTrace) { $ex.ScriptStackTrace } else { $ex.StackTrace }
$PSCmdlet.WriteInformation(@(
@Jaykul
Jaykul / ErrorHandlingExample.ps1
Last active March 7, 2018 19:19
Try this example, then try changing line 14 to catch [exception]
using namespace System.Management.Automation
& {
[CmdletBinding()]param()
$ErrorActionPreference = "Stop"
try { # Standard practice in every script
Get-Item NoSuchFile
} catch [ItemNotFoundException] {
Write-Warning "File not found, using workaround ... "
@Jaykul
Jaykul / Set-CodeCmd.ps1
Last active March 7, 2018 19:21
This makes it so you can type just `code` to start VS Code (even Insiders) in the current folder, even ... in Explorer!
#requires -RunAsAdministrator
<#
.Synopsis
Creates (or alters) a "code" command for opening Visual Studio Code (or VS Code Insiders)
.Description
Recreates the "code.cmd"" batch file command that starts Visual Studio Code (or VS Code Insiders)
1. Adds logic to make it open in the current folder if you don't pass parameters.
2. Makes "code" work as a command in Windows 10 Explorer's address bar.
#>
[CmdletBinding()]