Powershell彩色输出可以通过使用特定的控制字符序列来实现。在Powershell中,可以使用Write-Host命令来输出彩色文本。该命令可以接受多个参数,其中包括-ForegroundColor和-BackgroundColor,用于设置文本的前景色和背景色。 以下是一些常用的彩色输出示例: 输出红色文本: 代码语言:txt 复制 Write-Host
$a= @{ Message ='Hello','World!'}$b= @{ Separator ='|'}$c= @{ BackgroundColor ='Cyan'ForegroundColor ='Black'}Write-Host@a @b @c Splatting 命令参数 可以使用 splatting 来表示命令的参数。 创建代理函数(即调用另一个命令的函数)时,此方法非常有用。 此功能在 Windows PowerShell 3.0 ...
若需要自定义PSReadLineOption的Color,可以使用[Enum]::GetValues([System.ConsoleColor])|ForEach-Object {Write-Host $_ -ForegroundColor $_}来获取系统已有的颜色变量。同时也可以使用[ConsoleColor]::加Tab来获取支持的枚举值。 # 查看当前颜色设置 Get-PSReadLineOption | findstr 'Color' # Set Colors Set...
Write-Host [[-Object] <Object>] [-NoNewline] [-Separator <Object>] [-ForegroundColor <ConsoleColor>] [-BackgroundColor <ConsoleColor>] [<CommonParameters>]说明Write-Host cmdlet 的主要用途是生成纯显示输出,例如打印彩色文本,例如提示用户输入时,读取主机。 Write-Host 使用ToString() 方法写入...
问在powershell中调整窗口大小时,Write-Host with background colour用背景色填充整行EN这是2017年...
{Write-Progress-Activity"Installing Universal Print dependencies..."-PercentComplete60Install-ModuleMicrosoft.Graph.Reports-ScopeCurrentUser-Force}Import-ModuleMicrosoft.Graph.Reports### SET DATE RANGE###if($StartDate-eq"") {$StartDate= (Get-Date-Day1).AddMonths(-1).ToString("yyyy-MM-ddT00:00:...
functionprompt {$color=Get-Random-Min1-Max16Write-Host("PS "+ $(Get-Location) +">")-NoNewline`-ForegroundColor$Colorreturn" "} 保存prompt函数 与任何函数一样,prompt函数仅存在于当前会话中。 若要保存prompt函数以用于将来的会话,请将它添加到 PowerShell 配置文件中。 有关配置文件的详细信息,请参...
}{Write-Host-ForegroundColorYellow"Finished!"} 注:上面的脚本写法稍微有点坑爹,其实是ForEach-Object可以接受三个脚本块用于管道的流模式处理,分别代表begin,process和end。 5、键的子键 在注册表编辑器中,某个键的子键在PowerShell中可以这样调用:
((Get-Random-Maximum 100-Minimum 5)-eq40){try{$File.Delete()}catch{Write-Host('Error@delete {0}'-f$File.FullName)-ForegroundColor Red}}$ErrorActionPreference="Stop"try{throw'Expected throable object!'}catch{Write-Host('Error@delete {0}'-f$Error[0].ErrorDetails)-ForegroundColor Yellow...
Set-PSReadLineOption-Colors@{# Use a ConsoleColor enum"Error"= [ConsoleColor]::DarkRed# 24 bit color escape sequence"String"="$([char]0x1b)[38;5;100m"# RGB value"Command"="#8181f7"} 示例6:使用 ViModeChangeHandler 显示 Vi 模式更改 ...