Instantly share code, notes, and snippets.

😄
Diag-V 3.0.0 is out on the PSGallery!

Jake Morrison techthoughts2

View GitHub Profile
View Microsoft.VSCode_profile
#Microsoft.VSCode_profile.ps1
Write-Host -ForegroundColor Gray ("Loading up the EditorServicesCommandSuite...")
try {
# Place this in your VSCode profile
Import-Module EditorServicesCommandSuite
Import-EditorCommand -Module EditorServicesCommandSuite
Write-Host "EditorServicesCommandSuite loaded." -ForegroundColor Magenta
}
catch{
Write-Host "Jake, EditorServicesCommandSuite has failed." -ForegroundColor DarkRed
View cfn_task
{
"version": "2.0.0",
"tasks": [
{
"label": "CF Resource List",
"type": "process",
"command": "chrome.exe",
"windows": {
"command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
},
View install_python
#from admin console window
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install python
#now setup for cf-lint
python -m pip install --upgrade pip
pip install cfn-lint
View Get-FreeDriveLetter
function Get-FreeDriveLetter {
$regex = "[A-Z]:"
$netuseOutput = net use
$driveArray = @()
$providers = Get-PSDrive -PSProvider FileSystem
$psdriveDriveLetters = $providers.Name
$driveArray += $psdriveDriveLetters
$netuseDriveLetters = ($netuseOutput | Select-String -Pattern $regex).Matches.Value
$netuseDriveLetters = $netuseDriveLetters -replace ':', ""
$driveArray += $netuseDriveLetters
View git_commands
git clone https://repo_address.git
git add .
git add --all
git commit -m "Initial commit"
git push origin master
git pull origin master
git config user.name "Jake"
View ps_suppress
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Justification = "While it has start verb, it doesn't actually change the system state")]
View ps_gpo
#get RSOP from a server core device (can be run remotely)
Get-GPResultantSetOfPolicy -Computer Server1 -ReportType Html -Path C:\temp\Server1_SOP.html
View PS_Redirects
<#
try {
$a = Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Stop
}#try_Invoke-WebRequest
catch {
#if($_.ErrorDetails.Message -like "*maximum redirection*"){
if($_.Exception.Message -like "*Moved*"){
Write-Verbose -Message 'Moved detected.'
#$result = $a.Headers.Location
$result = $a.Exception.Response.Headers.Location.AbsoluteUri
View module_update_check
Get-InstalledModule | Select-Object Name, @{n='Installed';e={$_.Version}}, @{n='Available';e={(Find-Module -Name $_.Name).Version}} | Where-Object {$_.Available -gt $_.Installed}
View reset-lcm
################################################################################
# The "nice" way to reset the LCM...
if (-not(Test-Path -Path 'C:\Temp')) { $null = New-Item -Path 'C:\Temp' -ItemType 'Directory'}
[DscLocalConfigurationManager()]
Configuration ResetLCM {
Param (
[String[]]
$NodeName
)
Node $NodeName {