memo code

PowerShellのスクリプトコード
・サービスの状態を色分けして表示する。

#関数の定義
#引数としてサービスを受け取り、動作中のサービスは黄色
#停止状態のサービスは赤で表示する関数
#呼び出す関数は先に定義しておく必要がある
function showStatus
{
    if ($args[0].Status -eq "Running")
    {
        # サービス名を表示し、バディングする
        Write-Host ($args[0].ServiceName.PadRight(30) +
        $args[0].Status) -ForegroundColor Yellow
    }
    else
    {
        Write-Host ($args[0].ServiceName.PadRight(30) +
        $args[0].Status) -ForegroundColor Red
    }
    return
}

#スクリプトはここから開始
#サービスのリストを変数に格納
$services = Get-Service

#各サービス状態を表示
foreach($svc in $services)
{
    showStatus $svc
}
pause

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny

PAGE TOP