All Projects → stevencohn → Windowspowershell

stevencohn / Windowspowershell

Advanced PowerShell scripts and profile enhancements for common use cases

Programming Languages

powershell
5483 projects

Labels

Projects that are alternatives of or similar to Windowspowershell

iOS-Tweak-Dev-Tools
A collection of useful development tools and forks of tools that are geared towards iOS jailbreak developers.
Stars: ✭ 37 (+32.14%)
Mutual labels:  tweaks
gm-github-tweaks
Tweak GitHub to make it great again.
Stars: ✭ 15 (-46.43%)
Mutual labels:  tweaks
Win10 Initial Setup Script
PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
Stars: ✭ 4,494 (+15950%)
Mutual labels:  tweaks
Windows11-Optimization
Community repository, to improve security and performance of Windows 10 and windows 11 with tweaks, commands, scripts, registry keys, configuration, tutorials and more
Stars: ✭ 17 (-39.29%)
Mutual labels:  tweaks
BoringSSLKeys
Grab your libboringssl keys to decrypt traffic (pcaps)
Stars: ✭ 46 (+64.29%)
Mutual labels:  tweaks
Sophia-Script-for-Windows
⚡ The most powerful PowerShell module on GitHub for Windows 10 & Windows 11 fine-tuning and tweaking
Stars: ✭ 4,311 (+15296.43%)
Mutual labels:  tweaks
CLE
Command Live Environment
Stars: ✭ 21 (-25%)
Mutual labels:  tweaks
Regtweaks
Registry Tweaks for Windows.
Stars: ✭ 675 (+2310.71%)
Mutual labels:  tweaks
DDHTweaks
Tweak UI elements at run time to find the perfect values
Stars: ✭ 27 (-3.57%)
Mutual labels:  tweaks
Gamingtweaks
Windows 10 and (some) Linux Gaming Tweaks without myths
Stars: ✭ 463 (+1553.57%)
Mutual labels:  tweaks
WindowsRegistry
Windows Registry Tweaks & Hacks
Stars: ✭ 31 (+10.71%)
Mutual labels:  tweaks
King-Tweaks
No description or website provided.
Stars: ✭ 46 (+64.29%)
Mutual labels:  tweaks
Windows 10 Sophia Script
⚡ The most powerful PowerShell module on GitHub for Windows 10 & Windows 11 fine-tuning and tweaking
Stars: ✭ 4,133 (+14660.71%)
Mutual labels:  tweaks
TickrateChanger
A mod that changes the game speed
Stars: ✭ 39 (+39.29%)
Mutual labels:  tweaks
Optimizer
Make Windows faster and more secure
Stars: ✭ 489 (+1646.43%)
Mutual labels:  tweaks
Windows10Tools
Tools for Windows 10
Stars: ✭ 45 (+60.71%)
Mutual labels:  tweaks
chrome-flags
💐 My personal Chromium-based flags
Stars: ✭ 13 (-53.57%)
Mutual labels:  tweaks
Personal Tweaks
Tweaks that are extremely small, or are not really mine, but aren't forks either
Stars: ✭ 13 (-53.57%)
Mutual labels:  tweaks
Notcpucores
Work, Play, Stream - Without the Stutter. Download using Releases button below
Stars: ✭ 514 (+1735.71%)
Mutual labels:  tweaks
Howtopopbuntu
Tweaks for Debian & Ubuntu based Distro.
Stars: ✭ 267 (+853.57%)
Mutual labels:  tweaks

PowerShell Scripts

These scripts are my custom profile scripts for PS command windows and for ISE including a custom "Dark Selenitic" theme for ISE.

How to install

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/master/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.

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.

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.

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]

Report the account information for the given username and optionally a specified domain.

alt text

Get-ChildItemColorized -Dir d [-la]

Display a colorized directory listing along with total size. Aliased to ls

alt text

Get-Colors [-All] [-Cmd] [-PS] [-ConEmu] [-Script]

Display the console colors for Command console, PowerShell console, and ConEmu consoles.

alt text

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.

alt text

Get-Hosts

Display the /etc/hosts file, colorized.

Get-Installed [-Outfile f]

Report all installed applications registered on the local system.

Get-Network [-Preferred] [-Addresses] [-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.

alt text

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.

alt text

Get-Performance

Get and report performance metrics using the built-in WinSAT utility.

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.

Invoke-VsDevCmd

Invoke the Visual Studio environment batch script. Aliased to vs

New-CommandWrapper

Sepcial internal function from PowerShell Cookbook.

New-DriveMapping -DriveLetter d -Path p [-SourceDriveLabel s] [-DriveLabel l] [-Reboot] [-Force]

Create a persistent mapping of a folder to a new drive letter. (persistent SUBST)

New-Host -IP a -Name n

Adds or updates an entry in the Windows hosts file

New-VMClone -Name n -Path p -Template t [-Checkpoint]

Create a new VM from a registered VM or an exported VM.

PrettyPrint-File -Path p [-Dedent] [-Overwrite]

Format or pretty-pretty JSON and XML files.

Remove-DockerTrash [-Volumes]

Prune unused docker containers and dangling images.

Remove-DriveMapping -DriveLetter d [-SourceDriveLabel s] [-Reboot] [-Force]

Remove a persistent mapping of a folder created by New-DriveMapping.

Remove-Locked -Name n

Remove a System-owned file or directory. Attempts multiple approaches to remove stubborn items.

Repair-Path [-Yes]

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.

Restart-Bluetooth [-Show]

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-Colors -Theme t | [-Name n -Color c [-Bgr] [-Background] [-Foreground]] [-Cmd] [-ConEmu] [-PS]

Set the color theme for command line consoles or set a specific named color.

Set-ItemOwner -Path p [-Group g]

Set the ownership of an item - folder or file - to the specified user group.

Set-OutDefaultOverride

(Internal) Helper function for Get-ChildItemColorized.

Set-RegistryOwner -Hive h -Key k [-Recurse]

Set full-access ownership of a specified Registry key.

Show-ColorizedContent -Filename f [-ExcludeLineNumbers]

Type the contents of a PowerShell script with syntax highlighting.

alt text

Show-Docker [-Ps] [-Containers] [-Images] [-Volumes]

Show containers and images in a single command.

alt text

Start-VMUntilReady -Name n [-Restart] [-Restore]

Start the named VM, optionally restoring the latest snapshot, and waiting until the OS provides a stable heartbeat.

Test-Elevated [-Action a ] [-Warn]

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.

Test-RebootPending [-Report]

Check the pending reboot status of the local computer.

Update-Gits [-Branch b] [-Project p] [-Reset]

Scan all sub-folders looking for .git directories and fetch/pull each to get latest code.

Update-Profile

Quick command line to pull latest source of this WindowsPowerShell repo from Github and update the content in $home\Documents\WindowsPowerShell.

Initialize-Machine.ps1

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.

This script can optionally create a new local administrator so it runs in two phases:

  1. Log on as an administrator
  2. Download Initialize-Machine.ps1 to C:\Initialize-Machine.ps1
  3. Open an administrative PowerShell window
  4. PS> Set-ExecutionPolicy RemoteSigned
  5. PS> cd C:\
  6. PS> .\Initialize-Machine.ps1 -User <new-admin-username>
  7. ... Create new local administrator (y/n) [y]: y
  8. ... Password: *********
  9. ... Logout to log back in as <new-admin-username> (y/n) [y]: y
  10. Log on as <new-admin-username>
  11. Open an administrative PowerShell window
  12. PS> cd C:\
  13. 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.

Install-Programs.ps1

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] -AccessKey a -SecretKey s [-ListCommands] [-Extras] [-Enterprise]

  • command - optional argument to run a single command, default is to run all commands
  • -AccessKey - AWS access key used for downloading bits from S3 (only needed first time)
  • -SecretKey - AWS secret key used for downloading bits from S3 (only needed first time)
  • -ListCommands - this argument displays all available commands
  • -Extras - this argument causes extra applications to be installed
  • -Enterprise - install VS Enterprise; default is Professional

Note that the AccessKey and SecretKey arguments are only need the first time; they are used to log into AWS and are then stored using the awscli. Those apps below tagged with "[from S3]" are downloaded from S3 while all others are installed using chocolatey.

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) [from S3]
  • Curl
  • Docker Desktop
  • Git
  • Google Chrome
  • Greenshot
  • LINQPad
  • Macrium Reflect Free (installer)
  • mRemoteNG
  • Node.js (specific version)
  • Notepad++
  • Nuget command line
  • Robot3T
  • S3Browser
  • SourceTree
  • SysInternals procexp and procmon
  • Visual Studio 2019 and extensions (professional or enterpise) [from S3]
  • VSCode and extensions

Other applications included when -Extras is specified

  • DateInTray (installed to C:\tools) [from S3]
  • Paint.net
  • TreeSize Free
  • VLC
  • WiLMa (installed to C:\tools) [from S3]

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.

Reminders shown after a full install

Macrium Reflect

  1. Double-click the Macrium Installer icon on the desktop after VS is installed
  2. Choose Free on first screen, then Home version, and no registration is necessary

SourceTree configuration

  1. Log into choose "BitBucket" option and logon Atlassian online
  2. Enabled Advanced/"Configure automatic line endings"
  3. Do not create an SSH key

Visual Studio

  1. When installation is complete, rerun this script using the InstallVSExtensions command

.\Install-Programs.ps1 InstallVSExtensions

Consider these manually installed apps:

Profiles

Microsoft.PowerShell_profile.ps1

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.

Console Prompt Customization

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!

alt text

Microsoft.PowerShellISE_profile.ps1

This is the profile definition script fort the PowerShell ISE editor. It registers ISE add-ons found in the Modules\Addons folder.

Microsoft.VSCode_profile.ps1

This is the profile definition script for the VSCode integrated PowerShell terminal. It simply invokes the primary profile script above.

Dark Selenitic Scheme

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].