Creating a Security-Focused PowerShell and CMD Console for Windows
Transform your Windows command line experience with personalized, security-focused configurations for both PowerShell and CMD. This guide provides complete customization solutions that work even in restricted environments like Windows 10 IoT.
Overview
Whether you’re conducting security audits, managing systems, or performing daily administrative tasks, having a properly configured command line environment significantly improves productivity. This guide covers:
- Custom PowerShell profiles with security utilities
- Enhanced CMD configurations with auto-launch
- Security-focused aliases and functions
- Professional visual themes
- Compatibility with restricted environments
PowerShell Security Console
Creating Your Personalized Profile
Let’s build a comprehensive PowerShell profile tailored for security operations:
# Create a personalized profile for Anubhav@'# Anubhav's Security PowerShell Profile# ====================================
# Set colors - dark security-focused theme$Host.UI.RawUI.BackgroundColor = "Black"$Host.UI.RawUI.ForegroundColor = "White"$Host.PrivateData.ErrorForegroundColor = "Red"$Host.PrivateData.WarningForegroundColor = "Yellow"$Host.PrivateData.DebugForegroundColor = "Cyan"$Host.PrivateData.VerboseForegroundColor = "Green"
# Personalized security-focused promptfunction prompt { # Get last command status $lastCommand = $? $statusIndicator = if ($lastCommand) { "+" } else { "!" } $statusColor = if ($lastCommand) { "Green" } else { "Red" }
# Admin check $admin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544") $adminTag = if ($admin) { "[ADMIN] " } else { "" }
# Current path $path = $pwd.Path.Replace($HOME, "~")
# Current time for audit logging $time = Get-Date -Format "HH:mm:ss"
# Update window title with path info $Host.UI.RawUI.WindowTitle = "Anubhav - $path $adminTag"
# Multi-line prompt for better readability Write-Host "" Write-Host "[$time] " -NoNewline -ForegroundColor Cyan Write-Host $adminTag -NoNewline -ForegroundColor Yellow Write-Host "$path" -ForegroundColor Blue Write-Host "[$statusIndicator]" -NoNewline -ForegroundColor $statusColor return " > "}
# Useful security aliasesSet-Alias ping Test-ConnectionSet-Alias which Get-Command
# Security utility functionsfunction Test-Port { param($Computer, $Port) $conn = New-Object System.Net.Sockets.TcpClient try { $conn.Connect($Computer, $Port) Write-Host "Port $Port is OPEN on $Computer" -ForegroundColor Green return $true } catch { Write-Host "Port $Port is CLOSED on $Computer" -ForegroundColor Red return $false } finally { $conn.Dispose() }}
function Get-SystemInfo { $os = Get-CimInstance Win32_OperatingSystem $cs = Get-CimInstance Win32_ComputerSystem
Write-Host "OS: $($os.Caption) $($os.Version)" -ForegroundColor Green Write-Host "Boot Time: $($os.LastBootUpTime)" -ForegroundColor Green Write-Host "Uptime: $([math]::Round(($os.LocalDateTime - $os.LastBootUpTime).TotalHours, 2)) hours" -ForegroundColor Green Write-Host "Memory: $([math]::Round($cs.TotalPhysicalMemory / 1GB, 2)) GB" -ForegroundColor Green}
# Welcome bannerClear-HostWrite-Host "+-------------------------------------------+" -ForegroundColor BlueWrite-Host "| ANUBHAV'S SECURITY CONSOLE |" -ForegroundColor BlueWrite-Host "+-------------------------------------------+" -ForegroundColor BlueWrite-Host "* System : $([System.Environment]::OSVersion.VersionString)" -ForegroundColor GrayWrite-Host "* User : $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)" -ForegroundColor GrayWrite-Host "* PS Ver : $($PSVersionTable.PSVersion)" -ForegroundColor GrayWrite-Host ""Write-Host "[*] Type 'Get-SystemInfo' for system details" -ForegroundColor YellowWrite-Host "[*] Type 'Test-Port computer port' to check connectivity" -ForegroundColor YellowWrite-Host ""'@ | Set-Content -Path $PROFILE -Encoding ASCII
# Inform the user how to load the profileWrite-Host "Anubhav's profile created. To load it, run:" -ForegroundColor GreenWrite-Host 'powershell -ExecutionPolicy Bypass -NoExit -Command ". $PROFILE"' -ForegroundColor Yellow
Key Features of the PowerShell Profile
-
Enhanced Security Prompt:
- Shows current time for audit trails
- Displays admin status clearly
- Indicates last command success/failure
- Updates window title with context
-
Security Utility Functions:
Test-Port
: Quick port scanning capabilityGet-SystemInfo
: System security auditing- Custom aliases for common tasks
-
Professional Appearance:
- Dark theme optimized for long sessions
- Color-coded output for different message types
- Clean, organized welcome banner
-
Compatibility:
- Works in restricted environments
- Minimal dependencies
- Lightweight resource usage
Activating Your PowerShell Profile
To use this profile, run:
powershell -ExecutionPolicy Bypass -NoExit -Command ". $PROFILE"
CMD Security Console with Auto-Launch
For environments where PowerShell is restricted or when you prefer CMD, here’s a comprehensive solution:
Step 1: Create the Batch File
Create a file named AnubhavCMD.bat
with the following content:
@echo off:: Anubhav's Security-Focused CMD Setuptitle Anubhav's Security Consolecolor 0B
:: Clear screen with custom bannerclsecho.echo +------------------------------------------+echo ^| ANUBHAV'S SECURITY COMMAND LINE ^|echo +------------------------------------------+echo.echo * System: %OS%echo * User : %USERNAME%echo * Date : %DATE%echo.
:: Custom prompt with admin checknet session >nul 2>&1if %errorlevel% == 0 ( prompt $E[36m[$T]$E[0m [ADMIN] $E[94m$P$E[0m$_$E[92m^>$E[0m) else ( prompt $E[36m[$T]$E[0m $E[94m$P$E[0m$_$E[92m^>$E[0m)
:: Security aliasesdoskey ls=dir $*doskey clear=clsdoskey sysinfo=systeminfo ^| findstr /B /C:"OS" /C:"OS Version"doskey ports=netstat -an ^| findstr "LISTENING"doskey netinfo=ipconfig /alldoskey scan=ping $1
echo [*] Security commands: sysinfo, ports, netinfo, scanecho.
Save this file in your user profile folder: C:\Users\%USERNAME%\AnubhavCMD.bat
Step 2: Configure Auto-Launch
Create a setup script to enable automatic loading:
@echo offreg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "%USERPROFILE%\AnubhavCMD.bat" /fecho Registry key has been set! Close this window and open a new CMD to see your customized prompt.pause
Save this as SetupAutoRun.bat
and run it as administrator.
Step 3: Test Your Configuration
- Close any open Command Prompt windows
- Open a new Command Prompt
- Your custom configuration loads automatically
CMD Console Features
-
Security Commands:
sysinfo
: Quick OS informationports
: Show listening portsnetinfo
: Network configurationscan
: Ping utility wrapper
-
Enhanced Prompt:
- Shows current time
- Indicates admin privileges
- Color-coded for visibility
-
Professional Banner:
- Personalized header
- System information display
- Command reference
Advanced Customization Options
Adding More Security Functions to PowerShell
Extend your profile with additional utilities:
# Network Security Scannerfunction Get-OpenPorts { param($Target = "localhost", $StartPort = 1, $EndPort = 1000) Write-Host "Scanning $Target from port $StartPort to $EndPort..." -ForegroundColor Yellow
$StartPort..$EndPort | ForEach-Object { $port = $_ $tcp = New-Object System.Net.Sockets.TcpClient try { $tcp.Connect($Target, $port) Write-Host "Port $port : OPEN" -ForegroundColor Green $tcp.Close() } catch { # Port closed or filtered } }}
# Process Security Checkerfunction Get-SuspiciousProcesses { Get-Process | Where-Object { $_.Path -eq $null -or $_.Company -eq $null -or $_.Path -like "*\Temp\*" } | Select-Object Name, Id, Path, Company}
# Quick Security Auditfunction Start-SecurityAudit { Write-Host "=== Security Audit ===" -ForegroundColor Yellow
# Check Windows Defender status Get-MpComputerStatus | Select-Object AntivirusEnabled, RealTimeProtectionEnabled, IoavProtectionEnabled
# Check firewall status Get-NetFirewallProfile | Select-Object Name, Enabled
# Check for suspicious scheduled tasks Get-ScheduledTask | Where-Object {$_.Author -notlike "*Microsoft*"} | Select-Object TaskName, Author, State}
Enhancing CMD with More Aliases
Add these to your AnubhavCMD.bat
:
:: Additional security aliasesdoskey firewall=netsh advfirewall show allprofilesdoskey services=sc query state= alldoskey processes=tasklist /vdoskey connections=netstat -anobdoskey users=net userdoskey shares=net sharedoskey startup=wmic startup get caption,commanddoskey patches=wmic qfe list brief
Security Best Practices
1. Profile Security
- Store profiles in protected directories
- Avoid hardcoding sensitive information
- Use environment variables for paths
- Regularly review and update profiles
2. Execution Policy Management
For PowerShell, understand execution policies:
# Check current policyGet-ExecutionPolicy
# Set policy for current userSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
3. Logging and Auditing
Enable PowerShell transcription for security auditing:
# Add to profile for automatic loggingStart-Transcript -Path "$env:USERPROFILE\Documents\PSTranscripts\$(Get-Date -Format 'yyyyMMdd-HHmmss').txt"
Troubleshooting Common Issues
PowerShell Profile Not Loading
-
Check profile path:
Terminal window $PROFILETest-Path $PROFILE -
Verify execution policy allows scripts
-
Ensure profile file has correct encoding
CMD Customization Not Working
-
Verify registry key:
Terminal window reg query "HKCU\Software\Microsoft\Command Processor" /v AutoRun -
Check batch file path is correct
-
Ensure no syntax errors in batch file
Color Codes Not Displaying
For modern Windows 10/11, enable ANSI color support:
reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1
Conclusion
A well-configured command line environment is essential for efficient security operations and system administration. These customizations provide:
- Enhanced Productivity: Quick access to security tools and information
- Better Visibility: Clear indication of privilege levels and system state
- Professional Appearance: Clean, organized interface for daily work
- Flexibility: Works across different Windows environments
Whether you’re using PowerShell or CMD, these configurations create a personalized, security-focused workspace that adapts to your workflow. The modular approach allows you to add or modify features as your needs evolve, ensuring your command line environment remains an effective tool in your security arsenal.
Remember to regularly update your profiles with new functions and utilities as you discover useful patterns in your daily work. A personalized command line is not just about aesthetics—it’s about creating an efficient, secure workspace tailored to your specific needs.