0

I need a script that fetches the information and generates an HTML document. I'm looking for a way to make the columns of my report more friendly so I saw that it is possible to change them with [PSCustomObject] but after I go through this process the data. "System.Object[]" appears instead of the information. Can you help me?

$proc = Get-Process | select "ProcessName","ID"
$proc = foreach ($Procs in $proc) {
      [PSCustomObject]@{
          'Process Name' = $proc.processname
          'identification' = $proc.id          
      }  
    }
$out = $proc | ConvertTo-Html -Property "Process Name","identification"
$out | Out-File -FilePath "c:\temp\file.html"

enter image description here

1
  • 1
    You're enumerating over $proc and your item is $Procs yet on each loop iteration you're assigning the entire collection ( $proc) to your object's properties Commented May 8, 2022 at 16:46

1 Answer 1

1

Try this, it works for me :)

$objects=@()

$processes = Get-Process | select "ProcessName","ID"
foreach ($proc in $processes) {
      $objects+=[PSCustomObject]@{
          'Process Name' = $proc.processname
          'identification' = $proc.id          
      }  
}

$out = $objects | ConvertTo-Html
$out | Out-File -FilePath "c:\temp\file.html"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help. Your answer was exactly what I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.