Because of the ExpandProperty. That causes the Select to return [DateTime] instead of [Process]
Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Crawford, Scott [mailto:[email protected]] Sent: Tuesday, November 22, 2011 8:53 PM To: NT System Admin Issues Subject: RE: PSKill Get-Process <process-name> | Sort -Property StartTime | Select -First 1 | Stop-Process -Force Why doesn't it work to pipe your result into stop-process? I get: Get-Process notepad | Sort -Property StartTime | Select -Last 1 -ExpandProperty StartTime | Stop-Process Stop-Process : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:1 char:105 + Get-Process notepad | Sort -Property StartTime | Select -Last 1 -ExpandProperty StartTime | Stop-Process <<<< + CategoryInfo : InvalidArgument: (11/22/2011 7:46:52 PM:PSObject) [Stop-Process], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.StopProcessCommand Even if I change to pass the Id: Get-Process notepad | Sort -Property StartTime | Select -Last 1 -ExpandProperty Id | Stop-Process Stop-Process : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:1 char:98 + Get-Process notepad | Sort -Property StartTime | Select -Last 1 -ExpandProperty Id | Stop-Process <<<< + CategoryInfo : InvalidArgument: (6036:PSObject) [Stop-Process], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.StopProcessCommand -----Original Message----- From: Michael B. Smith [mailto:[email protected]]<mailto:[mailto:[email protected]]> Sent: Tuesday, November 22, 2011 6:56 PM To: NT System Admin Issues Subject: RE: PSKill Get-Process <process-name> | Sort -Property StartTime | Select -Last 1 -ExpandProperty StartTime Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com -----Original Message----- From: Ben Scott [mailto:[email protected]]<mailto:[mailto:[email protected]]> Sent: Tuesday, November 22, 2011 7:30 PM To: NT System Admin Issues Subject: Re: PSKill On Tue, Nov 22, 2011 at 7:23 PM, N Parr <[email protected]<mailto:[email protected]>> wrote: > Is there a way to kill the oldest process of multiple identical > process'? Looks like PSkill will just kill them all. Maybe get the > id's of the identical process and script it to kill the oldest identifier? You can't just pick the lowest PID, as PIDs aren't guaranteed to always increase, AFAIK. You'd need to look at the process start time. PowerShell prolly already has some obscure option to do it. ;) -- Ben ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to [email protected]<mailto:[email protected]> with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to [email protected]<mailto:[email protected]> with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to [email protected]<mailto:[email protected]> with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to [email protected] with the body: unsubscribe ntsysadmin
