Skip to content

Instantly share code, notes, and snippets.

View Woznet's full-sized avatar

Woz Woznet

  • VA
  • 08:59 (UTC -05:00)
View GitHub Profile
@Woznet
Woznet / ISE-Addons.ps1
Last active February 1, 2021 10:22
PowerShell ISE Addons
# ISE Addons
if (-not ($psISE)){
throw 'Must run in PowerShell ISE'
}
#region Helper Functions
$null = Add-Type -AssemblyName Microsoft.PowerShell.GPowerShell,WindowsBase,Microsoft.VisualBasic,PresentationCore
@Woznet
Woznet / send-sshkey.sh
Last active September 15, 2019 22:52
send ssh-key to remote machine through ssh
# Command to place id_rsa.pub file in the correct location on remote server
cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
@Woznet
Woznet / Add_Edit_with_PowerShell_ISE_as_administrator_context_menu.reg
Last active March 4, 2021 02:34
Change PowerShell File Context Menu Edit to Edit as Admin
Windows Registry Editor Version 5.00
; Created by: Woz
; Created on: December 22 2019
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Edit]
"NoSmartScreen"=""
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Edit\Command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd -ArgumentList '/s,/c,start PowerShell_ISE.exe \"\"%1\"\"' -Verb RunAs\""
@Woznet
Woznet / Git-Clone-All-Repos.sh
Last active February 23, 2020 09:31
Class all github user repositories
#!/bin/bash
# Clone all github.com repositories for the specified user.
# Validate username was specified
if [ $# -eq 0 ]
then
echo "Usage: $0 <user_name> "
exit;
fi
@Woznet
Woznet / save-winkey.vbs
Last active March 4, 2021 02:32
Windows 10 Show License Key on Screen
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
WinLicKey = ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
' Change path in line below to save win-key.txt in another location
outFile = WshShell.ExpandEnvironmentStrings("%UserProfile%") + "\Desktop\win-key.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
@Woznet
Woznet / AutoUpgrade-Win7to10.ps1
Created February 4, 2020 22:01
Download and Install Windows 10 9252
#Requires -Version 5.1
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process -FilePath powershell.exe -ArgumentList '-File',('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
exit
}
$file = Join-Path -Path $PSScriptRoot -ChildPath 'Windows10Upgrade9252.exe'
if (Test-Path -Path $file){
@Woznet
Woznet / Error Management.ps1
Last active February 9, 2023 09:20
PowerShell - Try/Catch with ErrorRecord Info
# Error Management
try {
Made-to-Fail
}
catch {
[System.Management.Automation.ErrorRecord]$e = $_
[PSCustomObject]@{
Type = $e.Exception.GetType().FullName
Exception = $e.Exception.Message
Reason = $e.CategoryInfo.Reason
#Requires -RunAsAdministrator
@(
"$env:windir\System32\WindowsPowerShell\v1.0\profile.ps1",
"$env:windir\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1",
"$env:windir\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1",
"$env:USERPROFILE\Documents\WindowsPowerShell\profile.ps1",
"$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1",
"$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1"
).ForEach({
@Woznet
Woznet / profile.ps1
Last active November 10, 2024 09:47
PowerShell Profile
#Requires -Version 5
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
using namespace Microsoft.PowerShell
#~~#~~#~~#~~#~#~~#~~#~~#~~#~#~~#~~#~~#~~#~#~~#~~#~~#~~#
$FormatEnumerationLimit = -1
#~~#~~#~~#~~#~#~~#~~#~~#~~#~#~~#~~#~~#~~#~#~~#~~#~~#~~#
# Chocolatey profile
$ChocolateyProfile = Join-Path -Path $env:ChocolateyInstall -ChildPath 'helpers\chocolateyProfile.psm1' -Resolve -ErrorAction Ignore
if ($ChocolateyProfile) { Import-Module -Global -Name $ChocolateyProfile -PassThru:$false -ErrorAction SilentlyContinue -WarningAction Ignore }
@Woznet
Woznet / Uninstall-Older-Module-Versions.ps1
Created October 28, 2020 19:43
Uninstall the older versions of a module
# https://www.myerrorsandmysolutions.com/how-to-uninstall-older-versions-of-a-powershell-module-installed/
param(
[Parameter(Mandatory)]
[string]$ModuleName
)
$Latest = Get-InstalledModule -Name $ModuleName
Get-InstalledModule -Name $ModuleName -AllVersions | Where-Object {$_.Version -ne $Latest.Version} | Uninstall-Module -Confirm