Skip to content

Instantly share code, notes, and snippets.

View Tiberriver256's full-sized avatar
📚
Still learning

Micah Rairdon Tiberriver256

📚
Still learning
View GitHub Profile
@Tiberriver256
Tiberriver256 / FindPortProcessName
Created March 12, 2019 14:32
Find what process is using a port on Windows
$Port = "8080"
netstat -a -n -o | where { $_ -match $Port } | foreach {
$Process = Get-Process -PID (($_ -replace "\s+"," ") -split " ")[-1]
"Process: $($Process.ProcessName) ($($Process.Id)) is using $Port"
}
@Tiberriver256
Tiberriver256 / setup.ps1
Last active November 15, 2023 02:18
My Ubuntu development environment setup script
#!/bin/pwsh
Install-Module -Name Get-ChildItemColor, oh-my-posh, posh-git, nvm -Force
md ~\.config\powershell
"Set-Theme -name Darkblood" | Out-File $Profile -Append
Install-NodeVersion 8
Install-NodeVersion 10
@Tiberriver256
Tiberriver256 / boxstarter
Last active January 5, 2024 08:25
My personal development environment configuration
# Configure Windows
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar
Update-ExecutionPolicy Unrestricted
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name Get-ChildItemColor,posh-git,terminal-icons -Force
## Git
winget install -e --accept-source-agreements --silent --accept-package-agreements --id Git.Git
@Tiberriver256
Tiberriver256 / Set-Transparency.ps1
Last active March 6, 2024 03:49
Make any window transparent using PowerShell. Modified from https://gist.github.com/grenade/ed8dd77ae8eeb5b4a3c1cfd66e9c8ae7
$user32 = Add-Type -Name 'user32' -Namespace 'Win32' -PassThru -MemberDefinition @'
[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, int bAlpha, uint dwFlags);
@Tiberriver256
Tiberriver256 / APlayingAroundWithKestrel.ps1
Last active March 2, 2023 00:24
Trying to get Kestrel working in PowerShell...
using namespace Microsoft.AspNetCore.Builder;
using namespace Microsoft.AspNetCore.Http;
using namespace System;
using namespace Microsoft.AspNetCore.Hosting;
# If you don't have Visual Studio Installed this should work fine
# Install-Package Microsoft.AspNetCore -Source nuget.org -Destination .\.nuget\packages
# Install-Package Microsoft.AspNetCore.Server.Kestrel -Source nuget.org -Destination .\.nuget\packages
$LibFolder = ""
@Tiberriver256
Tiberriver256 / lilPowerShellNotepadSearcher.ps1
Last active January 14, 2024 07:04
This is a tiny little PowerShell script that will find any files you have open in Notepad and present them in out-gridview with lines to help with searching. Large files it will prompt you for a pre-search term or a regex to make it usable in out-gridview. Super handy for when you get logs in Outlook and don't want to save them to somewhere spec…
$FilePaths = @()
$FilePaths = (Get-WmiObject win32_process -filter "name like 'notepad.exe'") |
foreach { ($_.commandline -split " ",2)[1] }
if($FilePaths.count -gt 1) {
$FilePath = $FilePaths | Out-GridView -PassThru -Title "Select the open file you would like to search"
} else {
$FilePath = $FilePaths
}
@Tiberriver256
Tiberriver256 / PowerShellNTFSStaticFileServer.ps1
Last active January 5, 2024 08:23
This script starts a small web server listening on localhost:8080 that will impersonate the authenticated user and serve static content. This means if they do not have NTFS permissions to the file they will get an access denied or a 404 file not found if they do not have NTFS access to list contents of the directory.
function Get-DirectoryContent {
<#
.SYNOPSIS
Function to get directory content
.EXAMPLE
Get-DirectoryContent -Path "C:\" -HeaderName "poshserver.net" -RequestURL "http://poshserver.net" -SubfolderName "/"
@Tiberriver256
Tiberriver256 / LicenseSKUToNameMappingHash.ps1
Last active May 10, 2023 22:04
LicenseSKUToNameMapping HashTable
$LicenseSKUToNameMapping = @{
'SHAREPOINTENTERPRISE_MIDMARKET' = 'SharePoint Online (Plan 1)'
'ESKLESSWOFFPACK_GOV' = 'Microsoft Office 365 (Plan K2) for Government'
'AAD_BASIC' = 'Azure Active Directory Basic'
'AAD_BASIC_AAD_BASIC' = 'Azure AD Basic - Azure Active Directory Basic'
'AAD_BASIC_EDU' = 'Azure Active Directory Basic for EDU'
'AAD_EDU' = 'Azure Active Directory for Education'
'AAD_PREMIUM' = 'Azure Active Directory Premium P1'
'AAD_PREMIUM_AAD_PREMIUM' = 'Azure AD Premium P1 - Azure AD Premium P1'
'AAD_PREMIUM
@Tiberriver256
Tiberriver256 / PSWebServer.psm1
Last active March 6, 2024 03:49
Sample of making a simple webserver in PowerShell. If you have more complex needs checkout Pode (https://github.com/Badgerati/Pode) as a fully fledged PowerShell web server.
Function New-PSWebServer {
<#
.Synopsis
Creates a web server that will invoke PowerShell code based on routes being asked for by the client.
.Description
New-PSWebServer creates a web server. The web server is composed of a schema that defines the client's requests to routes where PowerShell code is executed.
Under the covers, New-PSWebServer uses the HTTPListener .NET class to execute powershell code as requested, retrieves the results and sends data back through the httplistener web server framework.
function new-PowershellWebGUI ($HTMLRaw,$Title,$Runspace) {
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="$Title" Height="500" Width="700">
<Grid>
<DockPanel>
<WebBrowser Name="WebBrowser" DockPanel.Dock="Top" Margin="30">
</WebBrowser>