How to exclude property from result returned by powershell command ?

Hello,

I have ran following command that works well ,however it returns   PSComputerName,RunspaceId, PSShowComputerNameproperties even if I dont select specifically.

Invoke-Command -ComputerName $serversinFarm -ScriptBlock ${function:Get-RemoteRebootStatus}

Would you please let me know how can I exclude RunspaceId, PSShowComputerName properties  in result ?

Thanks and Re

December 8th, 2014 2:41pm

Try below at end of command

| select -ExcludeProperty PSComputerName, RunspaceId, 

Free Windows Admin Tool Kit Click here and download it now
December 8th, 2014 3:07pm

Hello,

I have tried excluding that way already but still its appearing in result :( !!

Any alternative ?

December 8th, 2014 3:29pm

Then you're probably doing it wrong. Can you post your code?

Free Windows Admin Tool Kit Click here and download it now
December 8th, 2014 10:48pm

Agree with Alex, may be you are not coding it right....
December 9th, 2014 5:31am

Hi Alex and Inderjeet - You would be right as I am not able to exclude the properties for following script.

Kindly change the SPServers parameter and let me know how can I exclude the properties RunspaceId,PSShowComputerName ?

Thank you for your time !!

$SPservers = @("Server1","Server2")

#Get existing web apps url
[Array]$webApps = Get-SPWebApplication | Select Url
$webAppItems = @()
foreach($site in $webApps)
{
$webAppItems += $site.Url
}

function Get-SPWebApplicationResponseTime
{
    [CmdletBinding()]
    [OutputType([int])]
    Param
    (
        # Param1 help description
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        $WebApplications    
    )

    Begin
    {
       
    }
    Process
    {
				foreach($WebApplication in $WebApplications)
                {	
					try
                    {			    
						$Request = New-Object System.Net.WebClient
						$Request.UseDefaultCredentials = $true
						$Start = Get-Date
						$PageRequest = $Request.DownloadString($WebApplication)
						$TimeTaken = ((Get-Date) - $Start).Totalseconds
						$Request | Select @{Name='Web URL';Expression={$WebApplication}} , @{Name='Response Time in ms';Expression={$TimeTaken} }
						$Request.Dispose()											 
					}
                    
					catch{$_.Exception | Select ErrorRecord , stacktrace ; continue;}
             
				}		
	}
    
    End
    {
        
    }
}


#Get site collection response for SPServers
function Get-RemoteWebResponseTime
{
    [CmdletBinding()]
    [OutputType([int])]
    Param
    (
        # Param1 help description
        [Parameter(Mandatory=$true,
                   ValueFromPipeline = $true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        [system.String[]]
        $sites
    )

    Begin
    {
    }
    Process
    {
      
            foreach($site in $sites)
                {
                    Invoke-Command -ComputerName $SPservers -ScriptBlock ${function:Get-SPWebApplicationResponseTime } -ArgumentList $site
             
               }
    }
    End
    {
    }
}

$WebResponseTime = Get-RemoteWebResponseTime -sites $webAppItems | ConvertTo-Html -Fragment


ConvertTo-Html -Body "<font color = blue><H4><B>Report</B></H4></font>$WebResponseTime" -Title "SharePoint Farm Health Check Report" -CssUri C:\style.CSS | Out-File "E:\Reports\tTest.html"

Free Windows Admin Tool Kit Click here and download it now
December 9th, 2014 3:09pm

I know this is a little late, but I might have a little insight. I just ran into this issue.

Testing with:

PS:>(get-process | select -first 1) | Select-Object -ExcludeProperty Id

I get:

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName                         
-------  ------    -----      ----- -----   ------     -- -----------                         
   1001      54    87644     117376   363 ...49.44   4080 CcmExec    

But if I do:

PS:>(get-process | select -first 1) | Select-Object * -ExcludeProperty Id

__NounName                 : Process
Name                       : CcmExec
Handles                    : 1001
VM                         : 380211200
WS                         : 120193024
PM                         : 89747456
NPM                        : 55152
Path                       : C:\Windows\CCM\CcmExec.exe
Company                    : Microsoft Corporation
CPU                        : 14549.4375
FileVersion                : 5.00.8239.1000 (SCCM.150414-0330)
ProductVersion             : 5.00.8239.1000
Description                : Host Process for Microsoft Configuration Manager
Product                    : System Center 2012 Configuration Manager
PriorityClass              : Normal
HandleCount                : 1001
WorkingSet                 : 120193024
PagedMemorySize            : 89747456
PrivateMemorySize          : 89747456
VirtualMemorySize          : 380211200
TotalProcessorTime         : 04:02:29.4375000
BasePriority               : 8
ExitCode                   :
HasExited                  : False
ExitTime                   :
Handle                     : 3536
MachineName                : .
MainWindowHandle           : 0
MainWindowTitle            :
MainModule                 : System.Diagnostics.ProcessModule (CcmExec.exe)
MaxWorkingSet              : 1413120
MinWorkingSet              : 204800
Modules                    : {System.Diagnostics.ProcessModule (CcmExec.exe), System.Diagnostic
                             s.ProcessModule (ntdll.dll), System.Diagnostics.ProcessModule (ker
                             nel32.dll), System.Diagnostics.ProcessModule (KERNELBASE.dll)...}
NonpagedSystemMemorySize   : 55152
NonpagedSystemMemorySize64 : 55152
PagedMemorySize64          : 89747456
PagedSystemMemorySize      : 304048
PagedSystemMemorySize64    : 304048
PeakPagedMemorySize        : 502435840
PeakPagedMemorySize64      : 502435840
PeakWorkingSet             : 957083648
PeakWorkingSet64           : 957083648
PeakVirtualMemorySize      : 1173757952
PeakVirtualMemorySize64    : 1173757952
PriorityBoostEnabled       : True
PrivateMemorySize64        : 89747456
PrivilegedProcessorTime    : 00:24:54.5937500
ProcessName                : CcmExec
ProcessorAffinity          : 4095
Responding                 : True
SessionId                  : 0
StartInfo                  : System.Diagnostics.ProcessStartInfo
StartTime                  : 7/28/2015 3:07:01 AM
SynchronizingObject        :
Threads                    : {3960, 4028, 5616, 5572...}
UserProcessorTime          : 03:37:34.8437500
VirtualMemorySize64        : 380211200
EnableRaisingEvents        : False
StandardInput              :
StandardOutput             :
StandardError              :
WorkingSet64               : 120193024
Site                       :
Container                  :

I get everything but the Id property.

So, i think it has something to do with property sets. The property set overrides any select exclusion. This works for me as I want everything (*) but 3 properties. In your case, it might not be such a elegant solution. Creating your own property set/PSDefaultParameterValues might be a better option.
https://technet.microsoft.com/en-us/library/hh847819.aspx?f=255&MSPPError=-2147217396

July 31st, 2015 3:06pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics