【问题标题】:Powershell Beginner ScriptingPowershell 初学者脚本
【发布时间】:2022-11-14 04:00:06
【问题描述】:

我想编写一个脚本,如果值小于 15,则颜色为红色,如果值 = 15,则颜色为黄色,如果值大于 15,则颜色为深洋红色。我只是在试验 powershell。

我是一名数据科学专业的学生,​​不知道任何 powershell 脚本,只是想找点乐子。

【问题讨论】:

标签: powershell


【解决方案1】:

根据您的要求,我认为下面的 PowerShell 代码应该可以工作:

$random = 随机获取 - 最小值 0 - 最大值 20 如果($随机 -lt 15){ write-host "Number ist $random" -ForegroundColor Red } elseif ($random -eq 15) { write-host "Number ist $random" -ForegroundColor Green } elseif ($random -gt 15) { write-host "Number ist $random" -ForegroundColor DarkMagenta }

【讨论】:

    【解决方案2】:

    简单的 q&d(又快又脏)...

    14, 15 | 
    ForEach-Object {
        If ($PSItem -eq 15)
        {Write-Host "$($PSItem) is a match" -ForegroundColor Red}
        Else
        {Write-Warning -Message "$($PSItem) is not yet a match"}
    }
    
    # Results
    <#
    WARNING:  is not yet a match
    15 is a match
    #>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多