Author Posts

April 26, 2018 at 4:21 am

$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 
    }

April 26, 2018 at 12:09 pm

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 

April 26, 2018 at 1:11 pm

Alternately, you can use Select-Object:

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

April 26, 2018 at 1:29 pm

Sorry none of the solution is working.

April 26, 2018 at 2:30 pm

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. 🙂

April 26, 2018 at 5:15 pm

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

April 27, 2018 at 2:15 am

This works for me.

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