AntiMalware Status

Configure the Windows Powershell to display only the current folder name in the shell prompt

You would like to have customized [easyazon_link identifier=”B071RMR12G” locale=”US” tag=”wn0d5-20″] PowerShell [/easyazon_link]prompt on your new machine. Especially you do not want to see full path to your Script directory in the prompt. Here is how to configure your PowerShell profile on Windows 10 and display in prompt only the  current directory where all your [easyazon_link identifier=”B06WP8VCG3″ locale=”US” tag=”wn0d5-20″] PowerShell [/easyazon_link] scripts are located.

Your PowerShell profile is  located:

C:\%userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

You have used Set-Location command and your Scripts are located at

C:\%userprofile\Documents\PowerShell

Obviously you do not want to see the full path in PowerShell prompt like :

PS C:\YourName\Documnets\PowerShell>

How do you fix it ?
You will need to open the Microsoft.PowerShell_Profile.ps1 file and enter this function code into the file, save and restart PowerShell.

function prompt {
$p = Split-Path -leaf -path (Get-Location)
"$p> "
}

Now when you open your [easyazon_link identifier=”1633430294″ locale=”US” tag=”wn0d5-20″] PowerShell [/easyazon_link] you should see the change in prompt showing only the PowerShell directory like

PS PowerShell>

Here is how it looks in my case:

Here is my Profile file:

### My PowerShell Profile
Clear-host

Set-location 'C:\Users\john.doe\Dropbox\PowerShell\'
$global:foregroundColor = 'white'
$time = Get-Date
$psVersion= $host.Version.Major
$curUser= (Get-ChildItem Env:\USERNAME).Value
$curComp= (Get-ChildItem Env:\COMPUTERNAME).Value

Write-Host ""
Write-Host "*********************************************************"
Write-Host "Greetings, $curUser!" -foregroundColor $foregroundColor
Write-Host "It is: $($time.ToLongDateString())" `n
Write-Host "You're running PowerShell version: $psVersion" -foregroundColor Green
Write-Host "Your computer name is: $curComp" -foregroundColor Green `n
Write-Host "Happy scripting!" -foregroundColor Red `n
Write-Host "*********************************************************"

$LogicalDisk = @()
Get-WmiObject Win32_LogicalDisk -filter "DriveType='3'" | % {
$LogicalDisk += @($_ | Select @{n="Name";e={$_.Caption}},
@{n="Volume Label";e={$_.VolumeName}},
@{n="Size (Gb)";e={"{0:N2}" -f ($_.Size/1GB)}},
@{n="Used (Gb)";e={"{0:N2}" -f (($_.Size/1GB) - ($_.FreeSpace/1GB))}},
@{n="Free (Gb)";e={"{0:N2}" -f ($_.FreeSpace/1GB)}},
@{n="Free (%)";e={if($_.Size) {"{0:N2}" -f (($_.FreeSpace/1GB) / ($_.Size/1GB) * 100 )} else {"NAN"} }})
}
$LogicalDisk | Format-Table -AutoSize | Out-String

Write-Host "Bitlocker Status" -foregroundColor Green
Write-Host ""
manage-bde -status c:

function Get-Excuse {
(Invoke-WebRequest http://pages.cs.wisc.edu/~ballard/bofh/excuses -OutVariable excuses).content.split([Environment]::NewLine)[(get-random $excuses.content.split([Environment]::NewLine).count)]
}

# Customized view of Location
function prompt {
$p = Split-Path -leaf -path (Get-Location)
"$p> "
}

# launches the builtin Python web server for the current folder and fires up your browser
# Server website.htm

Function Serve ($page)
{
Start-Process python -ArgumentList "-m SimpleHTTPServer 8000"
Start "http://localhost:8000/$page"
}

You can add more functions into the profile file and customize your PowerShell prompt experience as you need 🙂

Leave a Reply