0

我有下面的代码....

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 

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

它还以红色突出显示服务名称,以绿色突出显示所需的服务和依赖服务。如下所示 ...

在此处输入图像描述

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

在此处输入图像描述

任何人都可以告诉我最好的方法吗?可以打码吗?

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

所有帮助表示赞赏。

4

1 回答 1

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 
于 2013-11-06T15:57:26.317 回答