Invoke-Command remove PSComputerName

Welcome Forums General PowerShell Q&A Invoke-Command remove PSComputerName

This topic contains 5 replies, has 3 voices, and was last updated by

 
Keymaster
2 years, 4 months ago.

  • Author
    Posts
  • #46719

    Participant
    Points: 0
    Rank: Member

    Hi

    I am trying to remove PSComputerName and RunspaceId from my output. I have tried -ExcludeProperty in different locations with no luck. I am guessing it is in my new PSObject?

    $XDArray = Invoke-Command -Computername $XDServers.MachineName -ScriptBlock {
    Add-PSSnapin C*
    $Admins = Get-AdminAdministrator
    ForEach ( $Admin in $Admins.Name ) {

    $AdminAdministrator = Get-AdminAdministrator -Name $Admin | Select Name,Rights
    $AdminAdministrator
    $XDSite = Get-XDSite | Select Name

    $XDProps = [ordered]@{'Name'=$AdminAdministrator.Name;
    'Rights'=$AdminAdministrator.Rights;
    'XDSite'=$XDSite.Name
    }
    New-Object -TypeName PSObject -Property $XDProps

    }}

    Name : test\testaccount
    Rights : {Full Administrator:All}
    XDSite : XDTest
    PSComputerName : TESTSERVER1
    RunspaceId : d7220e52-7724-4e71-b4e1-57a0c0f2a8db

    Thanks

  • #46721

    Participant
    Points: 0
    Rank: Member
    $XDArray | Select-Object -Property * -ExcludeProperty PSComputerName,RunspaceID

    I find that -ExcludeProperty works against the -Property parameter, and if the -Property parameter isn't defined it does nothing. I suspect that might be what you are running into.

  • #46726

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    Those properties are added by PowerShell, pretty much "at the last minute" as the results come back. You can't remove them inside the Invoke-Command because they don't exist there; you would need to remove them on your local computer, as it's receiving the results.

    Invoke-Command { whatever } | Select -Exclude This,That

  • #46800

    Participant
    Points: 0
    Rank: Member

    Thanks Craig you saved me again. Your probably not use to answering rubbish questions like mine but again I'm two weeks into learning the power of PowerShell.

  • #46819

    Participant
    Points: 0
    Rank: Member

    Cheers Don, I should of remembered that from your PowerShell CBT's as you did cover that (on info overload at the moment). By the way your PowerShell nuggets are the best. I knew zero about PowerShell couple of weeks back.

  • #46821

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    I appreciate that. I'm surprised they've left that content up since I moved to Pluralsight ;). But glad it worked for you.

The topic ‘Invoke-Command remove PSComputerName’ is closed to new replies.