Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Powershell-包括空格_C#_Powershell - Fatal编程技术网

C# Powershell-包括空格

C# Powershell-包括空格,c#,powershell,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`

我有下面的代码

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 
这段代码为我提供了在我的机器上运行的所有服务以及各种依赖项的列表

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

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

有谁能给我建议最好的方法吗?它能被编码吗

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


感谢所有帮助。

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

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