Close process which isn't invoked by Current Logged-in user

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Close process which isn't invoked by Current Logged-in user

Post by jvierra »

Don't use localhost.

No idea how you are using remoting.

This works just fine for me:
Invoke-Command {qwinsta} -computername ws702

User avatar
Abhishek_Paul
Posts: 24
Joined: Thu Apr 27, 2017 7:51 am

Re: Close process which isn't invoked by Current Logged-in user

Post by Abhishek_Paul »

Please check my last edited post.

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Close process which isn't invoked by Current Logged-in user

Post by jvierra »

You cannot convert plain text to a Csv.

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Close process which isn't invoked by Current Logged-in user

Post by jvierra »

Why make it so complicated. Just use Invoke and loop it on $computers.

Code: Select all

$computers |
	ForEach-Object{
		$activeuser = Invoke-Command -ScriptBlock { qwinsta } -computername $_ |
			Select-String 'active' |
			ForEach-Object{
				$_.Line.Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries)[1]
			}
		[pscustomobject]@{
		       ComputerName = $_
		       ActiveUser = $activeuser
		}
	} # | Export-Csv <file>

User avatar
Abhishek_Paul
Posts: 24
Joined: Thu Apr 27, 2017 7:51 am

Re: Close process which isn't invoked by Current Logged-in user

Post by Abhishek_Paul »

Hi Jvierra,
As usual, you are the champ :D
With little modification, it worked for me.I appreciate your help.

Thanks a zillion.

Locked