user1086159
user1086159

Reputation: 1055

Powershell - include blank spaces

I have the below code....

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 

This code gives me a list of all services being run on my machine and the various dependencies.

It also highlights the Service Name in RED and the Services Required and Services Dependent in GREEN. as shown below ...

enter image description here

what I want to do is separate the data output with blank lines after each service so that it looks like the below....

enter image description here

Can anyone advise me on the best way to do this? Can it be coded in?

I am trying to create a document to show what services we have and what dependencies etc.

All help appreciated.

Upvotes: 0

Views: 69

Answers (1)

PashaPash
PashaPash

Reputation: 2066

May be just an extra write-host will be enough?

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 

Upvotes: 1

Related Questions