This is just a quick little article on how to customize PowerShell. The comments should tell the entire story in the document. The script is also available for download below.


The script itself:

###########################################################################################
#                                                                                         #
# Most of this was copied from Don Pezet of ITPro.TV with some slight                     #
# modification. Feel free to modify this as needed for your environment.                  #
#                                                                                         #
# For more, visit: https://itpro.tv/course-library/powershell/powershell-profiles/        #
#                                                                                         #
# In order to make these changes persistent, store them in one of the following           #
# directories:                                                                            # 
#                                                                                         #
# Current User: %UserProfile%\Documents\WindowsPowerShell\Microsoft.PowerShellprofile.ps1 #
# All Users: %windir%\system32\WindowsPowerShell\v1.0\Microsoft.Power_Shellprofile.ps1    #
#                                                                                         #
# To automatically create the path for Current User, run the following command in PS:     #
# New-Item -path $profile -type file -force                                               #
#                                                                                         #
# Edit the new Microsoft.PowerShellprofile.ps1 file and copy in the commands from below.  #
#                                                                                         #
# This does not modify font size. This is done in PowerShell properties manually.         #
#                                                                                         #
# You will also have to run the following command to allow for scripting to work before   #
# making these changes:                                                                   #
# Set-ExecutionPolicy Unrestricted                                                        #
#                                                                                         #
#-----------------------------------------------------------------------------------------#
#                                                                                         #
# Created by: Don Pezet (support@itpro.tv)                                                #
# Modified by: D.J. Moore (powershellscript@djmoore.33mail.com)                           #
# Last Modified Date: 2018.09.02                                                          #
# Version: 1.0                                                                            #
#                                                                                         #
# 1.0: Re-creation, modification to include Prompt Location.                              #
#                                                                                         #
###########################################################################################

# Let's make sure we're running in an Admin console.
# Reference: https://blogs.technet.microsoft.com/heyscriptingguy/2011/05/11/check-for-admin-credentials-in-a-powershell-script/ 
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
 [Security.Principal.WindowsBuiltInRole] "Administrator"))
{
 Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
 Break
}

#-----------------------------------------------------------------------------------------#

# Copy everything below into your Microsoft.PowerShellprofile.ps1 file.

# This will make Notepad your default editor as an alias to "edit".
Set-Alias edit notepad.exe

#This will move us to the root of the drive. 
Set-Location C:\

# Let us set some variables.
$console = $host.UI.RawUI 
$scrollback = $console.BufferSize
$window = $console.WindowSize

# This will make the font gree and the background black.
$console.ForegroundColor = "green" 
$console.BackgroundColor = "black"

# This will make the Virtual Height Buffer 3000 lines and the Virtual Width Buffer 110 lines.
$scrollback.Height = 3000 
$scrollback.Width = 110 
$console.BufferSize = $scrollback #This applies the new Buffer settings.

# Time to bump up the History count.
$MaximumHistoryCount = 150 
 
# This will change the physical dimensions of the window on the desktop.
$window.Width = 110 
$window.Height = 35 
$console.WindowSize = $window #This applies the new size settings.

# Let us make Prompt look special and add the date.
function prompt { Write-Host ("PS [" + $(get-date) + "] $(Get-Location) >") -NoNewline -ForegroundColor Cyan 
return " " 
}

Clear-Host

Download the text file here: PowerShell_Customize_Script

I hope you find this as incredibly helpful as I did. Thank you to the great guys over at ITProTV and Don Pezet!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *