WindowsPowerShell
Advanced PowerShell scripts and profile enhancements for common use cases
Install / Use
/learn @stevencohn/WindowsPowerShellREADME
PowerShell Scripts
This repo contains my custom PowerShell profile scripts. It also contains scripts to automate the configuration of a new machine and installation of common apps and tools that I frequently use.
How to install
This entire repo can be overlayed ontop of your Documents\PowerShell folder.
As with all PowerShell scripts, you'll need to loosen up the execution policy on new machines.
try{
Set-ExecutionPolicy RemoteSigned -Force -Confirm:$false;
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force -Confirm:$false;
}catch{}
If starting from scratch on a fresh machine:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12';
$0 = 'https://raw.githubusercontent.com/stevencohn/WindowsPowerShell/main'
Invoke-WebRequest -Uri "$0/common.ps1" -OutFile C:\common.ps1;
Invoke-WebRequest -Uri "$0/Initialize-Machine.ps1" -OutFile C:\Initialize-Machine.ps1
Set PATH
Ensure that the scripts are discoverable by adding their folder to your System-wide environment variable definitions:
C:\Users\username\Documents\PowerShell\Modules\Scripts
Then execute Initialize-Machine:
. C:\Initialize-Machine.ps1 -Verbose
The script is re-entrant so can be run multiple times without a problem.
You can then delete these files since they exist in the Documents\WindowsPowerShell folder too:
rm C:\common.ps1 -Force;
rm C:\Initialize-Machine.ps1 -Force
Alternatives
Initialize-Machine downloads the repo to Documents\WindowsPowerShell. If you already have Git installed and would prefer to manually download the repo and run Initialize-Machine from there:
Set-Location $home\Documents;
git clone https://github.com/stevencohn/WindowsPowerShell.git
Or if you download the repo as a Zip file, you'll need to unblock all files after unzipping:
Get-ChildItem -Path "$home\Documents\WindowsPowerShell" -Recurse | Unblock-File
See also the other configuration scripts below.
Commands
These scripts are located in the Modules\Scripts folder.
Clear-Events [-Quiet]
Clear all events from the Windows Event Log.
Clear-Temp [-Quiet]
Clear the contents of TEMP, Windows\TEMP, and LocalAppData\TEMP.
Connect-AwsLogin [-Profile] [-Account] [-Device] [-Code]
Sign in to AWS CLI using MFA for the configured profile of an IAM user.
Confirm-Schema -XmlPath x -XsdPath s [-Namespace n]
Validates an XML file against a given schema definition file.
ConvertFrom-BinHex -Hex v -Unicode
Convert a BinHex encoded string back to its original string value.
ConvertFrom-Hex -Hex v
Convert a Hex string into an integer value. If the string contains six or eight characters then it is also interpreted as an ARGB value and each component part is displayed.
ConvertTo-Hex -R r [-G g] [-B b]
Convert integer values to a Hex string. If one integer is specified then it is converted. If three integers are specified then they are assumed to be RGB values and combined into a single Hex string.
ConvertTo-mp3 -InputPath p [-Bitrate r] [-FullQuality] [-Info] [-Yes]
Primarily used to convert .m4a audio files to .mp3
Copy-Console [-OutFile f] [-All] [-Rtf] [-Trim]
Copy the contents of the Powershell console window preserving color. Can be sent to an out file or pasted into Word or OneNote.
Copy-Playlist -Playlist p -Target t -WhatIf
Copies all music files referenced by the given playlist to the specified location. For example, this can be used to copy music in an .m3u playlist file to a USB thumbdrive.
Edit-Hosts
Open the hosts file in Notepad.
Enable-MultiRdp [-MaxConnection m]
Patch termsrv.dll to allow multiple concurrent RDP connections to this machine
Edit-Playlist -Replace r [-Path p] [-Type t]
Replace the path of all items in a playlist file to the current user's MyMusic path.
Edit-PSProfile
Run VSCode with ~Documents\WindowsPowerShell as root folder. Aliased to ep
Enable-PersonalOneDrive
Enable Personal OneDrive sync when both Business and Personal accounts are registered on the local machine. Will indicate when either is account not available.
Enable-TrustedRemoting
Enable PowerShell remoting and trusted hosts for the current machine, typically run on a VM that will be used for automated tasks such as CI/CD.
Get-Account -Username u [-Domain d] [-SID] [-All]
Report the account information for the given username and optionally a specified domain.

Get-ChildItemColorized -Dir d [-la]
Display a colorized directory listing along with total size. Aliased to ls

Get-Colors [-All] [-Cmd] [-PS] [-ConEmu] [-Script]
Display the console colors for Command console, PowerShell console, and ConEmu consoles.

Get-CommandLine [-Name n] [-Only] [-ReturnValue] [-ShowSystem]
Report processes with their command lines, highlighting an optional search string
Get-Commits -Project p [-Branch b] [-Since yyyy-mm-dd] [-Last n] [-Raw] [-Graph]
Reports all commits for the given git repo after a specified date or within the last n days.
Get-DirSize -Dir d [-la]
Report the size of all items in the specified folder. Used as a sub-routine of Get-ChildItemColorized.
Get-DotNetVersion
Get the versions of.NET Framework installations on the local computer.
Get-Env [-Name n] [-Value v]
Report environment variables in colorized categoties with optional search highlighting.

Get-Hosts
Display the /etc/hosts file, colorized.
Get-Installed [-Store -Outfile f]
Report all installed applications registered on the local system, optionally including Store apps.
Get-Network [-Preferred] [-Addresses] [-WiFi] [-Verbose]
Determines the most likely candidate for the active Internet-specific network adapter on this machine. All other adpaters such as tunneling and loopbacks are ignored. Only connected IP adapters are considered. Wifi aliases are shown.

Get-ParentBranch
Determine the name of the nearest parent branch of the current branch in the local Git repo.
Get-Path [-Search s] [-Sort] [-Verbose]
Display the PATH environment variable as a list of strings rather than a single string and displays the source of each value defined in the Registry: Machine, User, or Process. Verbose mode dumps the User and System Paths as stored in the Windows Registry.

Get-Performance
Get and report performance metrics using the built-in WinSAT utility.
Get-Reboots [-Uptime]
List Windows Event Log events related to system reboots.
Get-Scripts
List all external scripts and their parameter names.
Get-Services [-Name n] [-Running || -Stopped]
Get a list of services ordered by status and name. Aliased to gs
Get-SpecialFolder [-Folder f] [-All]
Return the translation of a SpecialFolder by name or show all SpecialFolders with optional search highlighting.
Get-VMConfig -Path p [-Json]
Returns a VM configuration object of the specified .vmcx VM configuration file even if the VM is not attached to a Hyper-V server.
Install-BuildTools [-Force] [-Full] [-VsWhere]
Install minimal Microsoft build and test tools required for CI/CD.
Install-Chocolatey [-Upgrade]
Can be used on new machines to install Chocolately. If already installed then checks if it is outdated and prompts to update.
Install-Docker
Installs Docker for Windows, enabling Hyper-V as a prerequisite if not already installed.
Invoke-NormalUser -Command c
Execute a given command as a non-evelated context. Aliased to nu.
Convenient when you need to run as a normal user from an elevated prompt.
Invoke-SuperUser
Open a new command prompt in elevated mode. Aliased to su. Special command for ConEmu emulator.
New-Administrator -Username -Password
Create a new local admin user.
New-CommandWrapper
Sepcial internal function from PowerShell
