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.
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Fri Jun 15, 2018 2:04 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Fri Jun 15, 2018 2:04 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.
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked