PowerShell: how to get if else construct right?

后端 未结 2 490
太阳男子
太阳男子 2021-01-17 14:31

I\'m trying to learn powershell and tried to construct a if else statement:

if ((Get-Process | Select-Object name) -eq \"svchost\") {
    Write-Host \"seen\"         


        
2条回答
  •  离开以前
    2021-01-17 15:00

    You can simply ask Get-Process to get the process you're after:

    if (Get-Process -Name svchost -ErrorAction SilentlyContinue) 
    {
      Write-Host "seen"
    }
    else 
    {
      Write-Host "not seen"
    }
    

提交回复
热议问题