在Powershell中,可以使用Write-Host命令来输出彩色文本。该命令可以接受多个参数,其中包括-ForegroundColor和-BackgroundColor,用于设置文本的前景色和背景色。 以下是一些常用的彩色输出示例: 输出红色文本: 代码语言:txt 复制 Write-Host "Error occurred!" -ForegroundColor Red 输出绿色背景的白色文本: 代码语言:txt ...
Write-Host with background colour用背景色填充整行EN这是2017年conhost中的confirmed bug。所以,所有依...
functionShow-Color( [System.ConsoleColor] $color ) { $fore = $Host.UI.RawUI.ForegroundColor $Host.UI.RawUI.ForegroundColor = $color echo($color).toString() $Host.UI.RawUI.ForegroundColor = $fore } functionShow-AllColor { Show-Color('Black') Show-Color('DarkBlue') Show-Color('DarkGr...
$a= @{ Message ='Hello','World!'}$b= @{ Separator ='|'}$c= @{ BackgroundColor ='Cyan'ForegroundColor ='Black'}Write-Host@a @b @c Splatting 命令参数 可以使用 splatting 来表示命令的参数。 创建代理函数(即调用另一个命令的函数)时,此方法非常有用。 此功能在 Windows PowerShell 3.0 ...
Undo-Transaction Use-Transaction Write-EventLogMicrosoft.PowerShell.UtilityConvert-String ConvertFrom-StringPSDesiredStateConfigurationDisable-DscDebug Enable-DscDebug Get-DscConfiguration Get-DscConfigurationStatus Get-DscLocalConfigurationManager Publish-DscConfiguration Remove-DscConfigurationDocument Restore-DscConfig...
((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...
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 效果图如下所示: 说明:文件夹颜色参考如下: 不同颜色的文件夹可以为工作区域增添一些色彩和美感,他们可以使工作环境更加愉悦和舒适,提供工作满意度和生产力,谢...
Path-Appendif($Type-eq"Succeed") {Write-Host$logInfo-ForegroundColorGreen }elseif($Type-eq"Failed") {Write-Host$logInfo-ForegroundColorRed }elseif($Type-eq"Warning") {Write-Host$logInfo-ForegroundColorYellow }elseif($Type-eq"Start") {Write-Host$logInfo-ForegroundColorCyan }else{Wri...
{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:...
[void]writeLog($color,$logmessages){write-host -ForegroundColor $color $logmessages$logmessages >> $this.SavePath}[void]Trace($s){$msg = $this.getDataTime() + " [TRACE] " + $sif ($this.log){$this.writeLog('DarkGreen',$msg)}}[void]Info($s){$msg = $this.getDataTime() + "...