如何在 powershell v3 中创建数组



我想知道如何在 Power shell V3 中创建一个数组,以在本地计算机上生成带有字母 L 的软件列表以运行服务?

我不知道

您如何称呼本地计算机上的软件列表,但是以下代码为当前正在运行的计算机上所有Windows服务创建带有字母"L"的列表。

$services = @() # create an empty array
$services = Get-Service | ` # get a list of services
    foreach {
        # project each element in the list to a new object with two properties:
        @{
            IsRunning = (&{ # "L" if a service is active, i.e. in "Running" status
               if ($_.Status -eq "Running") { "L" } else { "" } # or "" otherwise
            })
            Name = $_.Name  # a name of a service
        }
    }

最新更新