0

This is a simplified example using Get-Process with a where clause. I have several HTML outputs I'm doing and I'd like to know if I can get the count of all objects limited by the where displayed in the HTML title called in the same line of code.

I don't want to do it in an additional line and was playing with Measure-Command and $_.count, but it was throwing away the data if I had it on the end of the pipe. Is anyone familiar with the syntax I should be using?

$processes = get-process | where { $_.name -like "s*"}

$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#CCCCCC}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:white}"
$a = $a + "</style>"

$processes | select * | convertto-HTML -head $a -body "<H2>Number of processes $_.count</H2>" | out-file c:\TEMP\COUNTTEST.htm

ii c:\TEMP\COUNTTEST.htm

I'd like the output to look like this(with the count of processes beginning with "S" in the title - 33 in this case):

----------------------------------
Number of processes 33

__NounName  Name            Handles VM          WS  
process      SCNotification 295     243159040   8953856 
Aldwoni
  • 1,168
  • 10
  • 24
user1854377
  • 33
  • 2
  • 5
  • 2
    Have you tried this `"

    Number of processes $($processes.Count)

    "` ?
    – beatcracker Dec 01 '15 at 20:45
  • That worked. is that all it was? Brackets and a preceding $? Thanks man! Why is the $ variable symbol in front of the brackets required? – user1854377 Dec 01 '15 at 21:21
  • The `$()` is called [subexpression](http://blogs.technet.com/b/stefan_stranger/archive/2013/09/25/powershell-sub-expressions.aspx), it used to evaluate code inside and output result. PS is smart enough to expand variables in strings, but when accessing object's properties inside quoted string you have to use subexpression. – beatcracker Dec 01 '15 at 22:06

0 Answers0