Powershell - 包括空格

时间:2013-11-06 15:49:17

标签: c# powershell

我有以下代码......

Get-Service -CN . | 
ForEach-Object { 
write-host -ForegroundColor 9 "Service name $($_.name)" 
if($_.DependentServices) 
{ write-host -ForegroundColor 3 "`tServices that depend on $($_.name)" 
  foreach($s in $_.DependentServices) 
   { "`t`t" + $s.name } 
} #end if DependentServices 
if($_.RequiredServices) 
{ Write-host -ForegroundColor 10 "`tServices required by $($_.name)" 
  foreach($r in $_.RequiredServices) 
   { "`t`t" + $r.name } 
} #end if DependentServices 
} #end foreach-object $o 

此代码为我提供了在我的机器上运行的所有服务的列表以及各种依赖项。

它还突出显示RED中的服务名称以及GREEN中所需的服务和服务。如下图所示...

enter image description here

我想要做的是在每个服务之后用空行分隔数据输出,使它看起来如下所示....

enter image description here

有人可以告诉我最好的方法吗?可以编码吗?

我正在尝试创建一个文档来显示我们拥有的服务以及依赖项等。

所有帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

可能只是一个额外的写主机就足够了吗?

Get-Service -CN . | 
ForEach-Object { 
write-host -ForegroundColor 9 "Service name $($_.name)" 
if($_.DependentServices) 
{ write-host -ForegroundColor 3 "`tServices that depend on $($_.name)" 
  foreach($s in $_.DependentServices) 
   { "`t`t" + $s.name } 
} #end if DependentServices 
if($_.RequiredServices) 
{ Write-host -ForegroundColor 10 "`tServices required by $($_.name)" 
  foreach($r in $_.RequiredServices) 
   { "`t`t" + $r.name } 
} #end if DependentServices 
write-host #new line
} #end foreach-object $o 
相关问题