These scripts are my custom profile scripts for PS command windows and for ISE including a custom "Dark Selenitic" theme for ISE.
This entire repo can be overlayed ontop of your Documents\WindowsPowerShell folder.
Set-Location $env:USERPROFILE\Documents;
git clone https://github.com/stevencohn/WindowsPowerShell.git
If downloading the repo as a Zip file then you'll need to unblock all files:
Get-ChildItem -Path "${env:USERPROFILE}\Documents\WindowsPowerShell" -Recurse | Unblock-File
To download just the Initialize-Machine.ps1 script:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12';
Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/stevencohn/WindowsPowerShell/main/Initialize-Machine.ps1' -OutFile C:\Initialize-Machine.ps1
Loosen up the execution policy. Consider signing the scripts and setting the execution policy to AllSigned.
Set-ExecutionPolicy RemoteSigned -Force -Confirm:$false;
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy UnRestricted -Force -Confirm:$false
See also the Install-Programs.ps1 script below.
These scripts are located in the Modules\Scripts folder.
Clear all events from the Windows Event Log.
Clear the contents of TEMP, Windows\TEMP, and LocalAppData\TEMP.
Convert a BinHex encoded string back to its original string value.
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.
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.
Primarily used to convert .m4a audio files to .mp3
Copy the contents of the Powershell console window preserving color. Can be sent to an out file or pasted into Word or OneNote.
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.
Open the hosts file in Notepad.
Replace the path of all items in a playlist file to the current user's MyMusic path.
Run VSCode with ~Documents\WindowsPowerShell as root folder. Aliased to ep
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 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.
Report the account information for the given username and optionally a specified domain.
Display a colorized directory listing along with total size. Aliased to ls
Display the console colors for Command console, PowerShell console, and ConEmu consoles.
Report processes with their command lines, highlighting an optional search string
Reports all commits for the given git repo after a specified date or within the last n days.
Report the size of all items in the specified folder. Used as a sub-routine of Get-ChildItemColorized.
Get the versions of.NET Framework installations on the local computer.
Report environment variables in colorized categoties with optional search highlighting.
Display the /etc/hosts file, colorized.
Report all installed applications registered on the local system.
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.
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 and report performance metrics using the built-in WinSAT utility.
List all external scripts and their parameter names.
Get a list of services ordered by status and name. Aliased to gs
Return the translation of a SpecialFolder by name or show all SpecialFolders with optional search highlighting.
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 minimal Microsoft build and test tools required for CI/CD.
Can be used on new machines to install Chocolately. If already installed then checks if it is outdated and prompts to update.
Installs Docker for Windows, enabling Hyper-V as a prerequisite if not already installed.
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.
Open a new command prompt in elevated mode. Aliased to su
. Special command for ConEmu emulator.
Invoke the Visual Studio environment batch script. Aliased to vs
Sepcial internal function from PowerShell Cookbook.
Create a persistent mapping of a folder to a new drive letter. (persistent SUBST)
Adds or updates an entry in the Windows hosts file
Creates a new elevated shortcut (.lnk file) to a given target
Create a new VM from a registered VM or an exported VM.
Format or pretty-pretty JSON and XML files.
Prune unused docker containers and dangling images.
Remove a persistent mapping of a folder created by New-DriveMapping.
Remove a System-owned file or directory. Attempts multiple approaches to remove stubborn items.
Clean up the PATH environment variable, removing duplicates, empty values, invalid paths, repairs variable substitutions, and moves paths between User and System paths appropriately. Verbose mode dumps the User and System Paths as stored in the Windows Registry.
Restarts the Bluetooth radio device on the current machine. This is useful when the radio stops communicating with a device such as a mouse. The alternative would be to reboot the system.
Set the color theme for command line consoles or set a specific named color.
Set the ownership of an item - folder or file - to the specified user group.
(Internal) Helper function for Get-ChildItemColorized.
Pins or unpins a target item to the Windows Taskbar (currently broken!)
Set full-access ownership of a specified Registry key.
Type the contents of a PowerShell script with syntax highlighting.
Show containers and images in a single command.
Start the named VM, optionally restoring the latest snapshot, and waiting until the OS provides a stable heartbeat.
Determine if the current session is elevated and displays a warning message if not. Can be run without the warning message and simply return a boolean result.
Check the pending reboot status of the local computer.
Scan all sub-folders looking for .git directories and fetch/pull each to get latest code.
Quick command line to pull latest source of this WindowsPowerShell repo from Github and update the content in $home\Documents\WindowsPowerShell.
This is a top-level script meant to be downloaded independently from this repo and run to configure and initialize new machines. This script will download this repo to the current user's Document folder, setting it up as the default PowerShell profile. Best to download it to and run from the root of C.
Run Set-ExecutionPolicy RemoteSigned
prior to running if this is the first use of PowerShell.
The Initialize-Machine script will download this repo into the MyDocuments folder, but if you have OneDrive enabled then the MyDocuments folder may differ from $home\Documents. So before initializing, you can create a junction point to MyDocuments using this command:
cd $home\Documents
cmd 'mklink /j WindowsPowerShell ([Environment]::GetFolderPath('MyDocuments'))
This script can optionally create a new local administrator so it runs in two phases:
- Log on as an administrator
- Download Initialize-Machine.ps1 to C:\Initialize-Machine.ps1
- Open an administrative PowerShell window
- PS>
Set-ExecutionPolicy RemoteSigned
- PS>
cd C:\
- PS>
.\Initialize-Machine.ps1 -User <new-admin-username>
- ... Create new local administrator (y/n) [y]:
y
- ... Password: *********
- ... Logout to log back in as <new-admin-username> (y/n) [y]:
y
- Log on as <new-admin-username>
- Open an administrative PowerShell window
- PS>
cd C:\
- PS>
.\Initialize-Machine.ps1 -Verbose
Finally, since this updates the PowerShell console colors, you can close and reopen the console to appreciate these fantastic new colors.
Automates the installation of applications, development tools, and other utilities. All applications, including Visual Studio, install unattended in about 25 minutes. It's also reentrant, skipping items already installed and installing items missing.
.\Install-Programs.ps1 [command] [-ListCommands] [-Extras] [-Enterprise] [-Verbose]
- command - optional argument to run a single command, default is to run all commands
- -AccessKey - optional, store your AWS access key in your private awscli config
- -SecretKey - optional, store your AWS secret key in your private awscli config
- -ListCommands - this argument displays all available commands
- -Extras - this argument causes extra applications to be installed
- -Enterprise - install VS Enterprise; default is Professional
- -Vebose - print extra information for each command
Hyper-V and the AWSCli are installed first. Hyper-V requires a reboot which is done automatically and the script picks up where it left off immediately after you log in again.
Default applications:
- Hyper-V (auto-reboots after install and the script continues upon logon)
- 7Zip
- Angular (specific version)
- AWSCli
- BareTail Free (installed to C:\tools)
- Curl
- Docker Desktop
- Git
- Greenfish Icon Editor Pro
- Greenshot
- LINQPad
- Macrium Reflect Free (installer)
- mRemoteNG
- Node.js (specific version)
- Notepad++
- Nuget command line
- Robot3T
- S3Browser
- SharpKeys
- SysInternals procexp and procmon
- Visual Studio 2019 and extensions (professional or enterpise)
- VSCode and extensions
- Windows Terminal
Other applications included when -Extras is specified
- Audacity audio editor
- DateInTray (installed to C:\tools)
- Dopamine music player
- Paint.net
- TreeSize Free
- VLC
- WiLMa (installed to C:\tools)
During the installation, hints and tips are shown highlighted in yellow and instructions are highlighted in cyan. Some are import, such as how to continue the manual installation of Macrium.
Macrium Reflect
- Double-click the Macrium Installer icon on the desktop after VS is installed
- Choose Free on first screen, then Home version, and no registration is necessary
SourceTree configuration
- Log into choose "BitBucket" option and logon Atlassian online
- Enabled Advanced/"Configure automatic line endings"
- Do not create an SSH key
Visual Studio
- When installation is complete, rerun this script using the InstallVSExtensions command
.\Install-Programs.ps1 InstallVSExtensions
Consider these manually installed apps:
- AVG Antivirus
- BeyondCompare (there is a choco package but not for 4.0)
- ConEmu
- OneMore OneNote add-in (https://github.com/stevencohn/OneMore/releases)
This the primary PowerShell profile definition script, run whenenver a new PowerShell command prompt is open or session is created. It defines aliases for some of the commands above. It also invokes special utilities unique to my environment such as integration with ConEmu, WiLMa, Chocolatey, and setting the intial working directory.
The PowerShell command prompt is customized as follows:
- It is rendered in blue
- It indicates the current working directory prefaced with "PS" for example
PS D:\code>
- If the console is elevated then the "PS" prefix is shown in red to highlight the fact that what do you, you do at your own risk!
This is the profile definition script fort the PowerShell ISE editor. It registers ISE add-ons found in the Modules\Addons folder.
This is the profile definition script for the VSCode integrated PowerShell terminal. It simply invokes the primary profile script above.
The Dark Selenitic.StorableColorTheme.ps1xml
file defines the Dark Selenitic color scheme for ISE. The theme is also
defined by the Themes\PSTheme_Selenitic.ps1 script.