function PS.UI ([string]$Title, [int]$WindowWidth, [int]$WindowHeight, [int]$BufferHeight, [string]$BackgroundColor, [string]$ForegroundColor){ # -- Registry Keys Path -- # $keys = @( "HKCU:\Console", "HKCU:\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe", "HKCU:\Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe" ) # -- Settings For All Keys -- # $settings = @{ # General Colors "ColorTable00" = 0x00000000 "ColorTable01" = 0x00da3700 "ColorTable02" = 0x000ea113 "ColorTable03" = 0x00dd963a "ColorTable04" = 0x001f0fc5 "ColorTable05" = 0x00562401 "ColorTable06" = 0x00f0edee "ColorTable07" = 0x00cccccc "ColorTable08" = 0x00767676 "ColorTable09" = 0x00ff783b "ColorTable10" = 0x000cc616 "ColorTable11" = 0x00d6d661 "ColorTable12" = 0x005648e7 "ColorTable13" = 0x009e00b4 "ColorTable14" = 0x00a5f1f9 "ColorTable15" = 0x00ffffff # Console Properties "FaceName" = "Lucida Console" "FontFamily" = 0x00000036 "FontWeight" = 0x00000190 "PopupColors" = 0x0000000f "ScreenBufferSize" = 0x03e80064 "ScreenColors" = 0x0000000f "WindowSize" = 0x001e0064 "FontSize" = 0x000c0007 "CursorType" = 0x00000001 "InterceptCopyPaste" = 0x00000001 "TerminalScrolling" = 0x00000000 "QuickEdit" = 0x00000001 "HistoryNoDup" = 0x00000001 "WindowAlpha" = 0x000000e6 } # -- Apply Settings To All Keys -- # foreach ($key in $keys) { if (!(Test-Path $key)) {ni -Path $key -Force | Out-Null} foreach ($name in $settings.Keys) { $value = $settings[$name] sp -Path $key -Name $name -Value $value -Type $(if ($value -is [int] -or $value -is [long]) {'DWord'} else {'String'}) } } # -- Native Methods Definition -- # Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; using System.Text; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct CONSOLE_FONT_INFO_EX { public uint cbSize; public uint nFont; public COORD dwFontSize; public uint FontFamily; public uint FontWeight; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string FaceName; } [StructLayout(LayoutKind.Sequential)] public struct COORD { public short X; public short Y; public COORD(short x, short y) { X = x; Y = y; } } public static class NativeMethods { [DllImport("kernel32.dll", SetLastError=true)] public static extern IntPtr GetStdHandle(int nStdHandle); [DllImport("kernel32.dll", SetLastError=true)] public static extern bool SetCurrentConsoleFontEx(IntPtr consoleOutput, bool maximumWindow, ref CONSOLE_FONT_INFO_EX info); [DllImport("kernel32.dll", SetLastError=true)] public static extern bool GetCurrentConsoleFontEx(IntPtr consoleOutput, bool maximumWindow, ref CONSOLE_FONT_INFO_EX info); } "@ Start-Sleep -Milliseconds 400 Clear-Host # -- Set Console Font -- # $handle = [NativeMethods]::GetStdHandle(-11) $font = New-Object CONSOLE_FONT_INFO_EX $font.cbSize = [System.Runtime.InteropServices.Marshal]::SizeOf($font) [NativeMethods]::GetCurrentConsoleFontEx($handle, $false, [ref]$font) | Out-Null $font.FaceName = "Lucida Console" $font.dwFontSize = New-Object COORD(0, 12) $font.FontFamily = 0x36 $font.FontWeight = 400 [NativeMethods]::SetCurrentConsoleFontEx($handle, $false, [ref]$font) | Out-Null # -- Set Console Title -- # if ([string]::IsNullOrEmpty($Title)) {$Title = "Powershell"} [console]::Title = $Title # -- Set Window Size -- # if ($WindowWidth -eq 0) {$WindowWidth = 100} if ($WindowHeight -eq 0) {$WindowHeight = 35} [console]::SetWindowSize($WindowWidth, $WindowHeight) # -- Set Buffer Size -- # if ($BufferHeight -eq 0) {$BufferHeight = $WindowHeight} [console]::SetBufferSize($WindowWidth, $BufferHeight) # -- Set Console Colors -- # if (![string]::IsNullOrEmpty($BackgroundColor)) {[console]::BackgroundColor = $BackgroundColor} if (![string]::IsNullOrEmpty($ForegroundColor)) {[console]::ForegroundColor = $ForegroundColor} Clear-Host }