Skip to content

Instantly share code, notes, and snippets.

View JasonMorgan's full-sized avatar

Jason Morgan JasonMorgan

View GitHub Profile
@JasonMorgan
JasonMorgan / TrustedHosts
Last active September 16, 2023 17:57
Setting and modifying Trusted Hosts with PowerShell
## Hey folks, this is just a quick walkthrough on modifying the trusted hosts property in WSMAN using Powershell
# By default PowerShell loads a PSDrive for the WinRM service
# We modify the trusted hosts property using the Set-Item cmdlet
Set-Item WSMan:\localhost\Client\TrustedHosts -value 192.168.1.13
#This sets the value to 192.168.1.13, it also overwrites any existing values
# If you want to set a subnet you can use the PowerShell wildcard character
Set-Item WSMan:\localhost\Client\TrustedHosts -value 192.168.1.*
@JasonMorgan
JasonMorgan / Using DSC
Created May 9, 2014 19:39
Use a DSC Configuration
This gist simply covers using a DSC configuration to configure an endpoint.
Load the DSC resource like any other function.
1. You can copy and paste the Configuration into a powershell console
2. You can dot source the script containing the configuration
EX: . c:\scripts\DSCConfiguration.ps1
Note - there are other ways as well but I have limited time...
Call the configuration by it's name and supply any parameters you need
Ex: CustomConfig -computername Host1 -outputpath c:\temp
function Set-EnvVariable
{
<#
.SYNOPSIS
Sets the value of an environment variable
.DESCRIPTION
This function will set the value of an environment variable. The default behavior is to overwrite the existing value. The concatenate switch will append the new value to the existing value.
.EXAMPLE
Set-EnvVariable -Name Path -Value C:\git -Concatenate
Adds, ";c:\git" to the path variable
function Get-OneDriveUrl {
param (
$sharingUrl
)
$base64Value = [System.Convert]::ToBase64String( [System.Text.Encoding]::UTF8.GetBytes($sharingUrl) )
$encodedUrl = "u!" + $base64Value.TrimEnd('=').Replace('/','_').Replace('+','-')
(Invoke-RestMethod -Uri "https://api.onedrive.com/v1.0/shares/$encodedUrl/root?expand=children").'@content.downloadUrl'
}
Thu Apr 20 23:03:31 UTC 2017
enum bump {
Major
Minor
Patch
}
function Update-CookbookVersion {
param (
[string]$path,
[bump]$bump = 'Patch'
$x = New-Object -COM WScript.Shell
Do
{
$x.SendKeys('{NUMLOCK}{NUMLOCK}')
Start-Sleep -Seconds 600
}
Until ($false)
@JasonMorgan
JasonMorgan / profile.ps1
Created September 15, 2017 18:12
Powershell profiule for PS Core
start-job -ScriptBlock {Update-Help -Force} | Out-Null
function ql { $args }
function qs { "$args" }
$Host.PrivateData.ErrorForegroundColor = 'magenta'
$Host.PrivateData.VerboseForegroundColor = 'cyan'
$host.ui.RawUI.WindowTitle = "Jason`'s Rocking PowerShell Console: $([Math]::Round((Get-Process -id $PID).WorkingSet/1mb,2)) MB Memory used"
function prompt {
$Branch = Get-GitBranch
if (! $Branch) {
"$((hostname).split('.')[0]):$(("$($PWD.path)" -replace $HOME,'~').split('/')[-1]) $ENV:USER $('>' * ($nestedPromptLevel + 1)) "
#requires curl
function grab-stories {
param ($username)
(curl -sL http://api.storify.com/v1/stories/$username |
ConvertFrom-Json).content.stories.foreach{curl -s -o "$($_.slug).html" "$($_.permalink)"}
}
{
"Working Directory" : "\/Users\/jason",
"Prompt Before Closing 2" : 0,
"Selected Text Color" : {
"Green Component" : 0,
"Red Component" : 0,
"Blue Component" : 0
},
"Rows" : 25,
"Ansi 11 Color" : {