I want to select all chrome.exe process which is not invoked by the currently logged-in user and kill them.
Basically, I want to clean cached user login details for all other users from chrome without closing the currently logged-in user's browser.
I need to do all these using PS-remoting
Till now, this is what I have done:
Code: Select all
Get-WmiObject -Class Win32_Process -Filter 'Name = "chrome.exe"' | ForEach-Object { $_.GetOwnerSID().SID }
Second, I need to get the SID of Currently logged in user :
Code: Select all
$UserProfiles = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*" | Where { $_.PSChildName -match "S-1-5-21-(\d+-?){4}$" } | Select-Object @{ Name = "SID"; Expression = { $_.PSChildName } }, @{ Name = "UserHive"; Expression = { "$($_.ProfileImagePath)\NTuser.dat" } }
# Add in the .DEFAULT User Profile
$DefaultProfile = "" | Select-Object SID, UserHive
$DefaultProfile.SID = ".DEFAULT"
$DefaultProfile.Userhive = "C:\Users\Public\NTuser.dat"
$UserProfiles += $DefaultProfile
# Loop through each profile on the machine</p>
Foreach ($UserProfile in $UserProfiles)
{
# Load User ntuser.dat if it's not already loaded
if(($ProfileWasLoaded = Test-Path Registry::HKEY_USERS\$($UserProfile.SID)))
{
Write-Host "$($UserProfile.SID)" -ForegroundColor yellow
}
}
So, I need to find a way to get Currently logged in user details & close the each chrome.exe process associated with it.All this has to be done using Powershell V2 & PS-remoting
Any other method or help is really appreciated.