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

Ask your Windows 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: 14068
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Tue Aug 22, 2017 8:45 am

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 » Tue Aug 22, 2017 8:53 am

Please check my last edited post.

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

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

Post by jvierra » Tue Aug 22, 2017 9:03 am

You cannot convert plain text to a Csv.

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

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

Post by jvierra » Tue Aug 22, 2017 9:14 am

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 » Wed Aug 23, 2017 12:05 pm

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

Thanks a zillion.

Locked