How to exclude RunspaceId & PSShowComputerName

Welcome Forums General PowerShell Q&A How to exclude RunspaceId & PSShowComputerName

This topic contains 6 replies, has 4 voices, and was last updated by

 
Participant
6 months, 3 weeks ago.

  • Author
    Posts
  • #99793

    Participant
    Points: 3
    Rank: Member
    $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 
        }
    
    
  • #99823

    Participant
    Points: 35
    Rank: Member

    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 
    
  • #99829

    Participant
    Points: 165
    Helping Hand
    Rank: Participant

    Alternately, you can use Select-Object:

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

    Participant
    Points: 3
    Rank: Member

    Sorry none of the solution is working.

  • #99838

    Participant
    Points: 165
    Helping Hand
    Rank: Participant

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

  • #99849

    Participant
    Points: 0
    Rank: Member

    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

    • #99855

      Participant
      Points: 3
      Rank: Member

      This works for me.

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

The topic ‘How to exclude RunspaceId & PSShowComputerName’ is closed to new replies.