How to exclude RunspaceId & PSShowComputerName

$style = @'
        
'@  
    Function Test {
    Invoke-Command -ComputerName (Get-Content E:\srvs.txt) -ScriptBlock {

    foreach ($Task in (Get-ScheduledTask -TaskPath "\Admintasks\").TaskName)
        {
    $Systax = Get-ScheduledTask -TaskName $Task  
    $Invokestate = (Get-ScheduledTask -TaskName $Task).State
    If ($Invokestate -notcontains 'Running')
    {
    [PSCustomObject]@{
    JobName = ($Systax).Taskname
    Status = (Get-ScheduledTask -TaskName $Task).State

                    } }
        } 
                                    } 
                                    } 
                                    
   
$DFSRReportNonHTML = Test
if ($DFSRReportNonHTML)
    {

    $Html = $DFSRReportNonHTML | ConvertTo-Html -Fragment 
    [string]$htmlMail = ConvertTo-HTML -Head $style -Body $html -PostContent "Created $(Get-Date) from $env:COMPUTERNAME" 
    }

if ($htmlMail)
    {
    Send-MailMessage 
    }

Select the values you want in the report, I’ve one I run like this

ConvertTo-Html -Property Ticket,ServerName,RunDate,JobName,StepName,Message -Head $style 

Alternately, you can use Select-Object:

$Html = $DFSRReportNonHTML | 
    Select-Object -ExcludeProperty RunspaceID, PSShowComputerName | 
    ConvertTo-Html -Fragment 

Sorry none of the solution is working.

Perhaps you should provide a sample of the output you are getting just before you convert it to HTML, so we can see where the gap is. :slight_smile:

Invoke-Command has a -HideComputerName parameter. Its a switch which does suppress the PSComputerName property

To suppress the RunSpaceId you need to do

Invoke-Command -Computername XXX -ScriptBlock {} | select * -exclude RunspaceID

or

Invoke-Command -Session XXX -ScriptBlock {} | select * -exclude RunspaceID

There is another, more complicated to code but easier to use, way but you’ll have to attend PowerShell Summit 2019 to discover what it is

This works for me.

Invoke-Command -Session XXX -ScriptBlock {} | select-object -Property Pr1,Pr2,Pr3