pixel0815
Goto Top

Per Powershell Benutzeranmeldung remote finden und abmelden

Hallo zusammen,

das Skript ist toll und funktioniert.
Momentan würde ich gerne nicht nur das Resultat sehen sondern auch gleich den Benutzer abmelden der da gesucht wird von den gefundenen Servern.
Ist das ein großer Aufwand?
Ich habe schon mit qwinsta herumgespielt aber leider ist dies nicht von erfolg gekrönt worden.


##############################################################################################
##  Find out what computers a user is logged into on your domain by running the script
##  and entering in the requested logon id for the user.
##
##  This script requires the free Quest ActiveRoles Management Shell for Active Directory
##  snapin  http://www.quest.com/powershell/activeroles-server.aspx
##############################################################################################

Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
$ErrorActionPreference = "SilentlyContinue"  

# Retrieve Username to search for, error checks to make sure the username
# is not blank and that it exists in Active Directory

Function Get-Username {
$Global:Username = Read-Host "Enter username you want to search for"  
if ($Username -eq $null){
	Write-Host "Username cannot be blank, please re-enter username!!!!!"  
	Get-Username}
$UserCheck = Get-QADUser -SamAccountName $Username
if ($UserCheck -eq $null){
	Write-Host "Invalid username, please verify this is the logon id for the account"  
	Get-Username}
}

get-username

$computers = Get-QADComputer -OSname '*Server*' | where {$_.accountisdisabled -eq $false}  
foreach ($comp in $computers)
	{
	$Computer = $comp.Name
	$ping = new-object System.Net.NetworkInformation.Ping
  	$Reply = $null
  	$Reply = $ping.send($Computer)
  	if($Reply.status -like 'Success'){  
		#Get explorer.exe processes
		$proc = gwmi win32_process -computer $Computer -Filter "Name = 'explorer.exe'"  
		#Search collection of processes for username
		ForEach ($p in $proc) {
	    	$temp = ($p.GetOwner()).User
	  		if ($temp -eq $Username){
			write-host "$Username is logged on $Computer"  
		}}}}

Vielen Dank schon mal :o)
Gruß
Heiko

Content-Key: 272941

Url: https://administrator.de/contentid/272941

Ausgedruckt am: 28.03.2024 um 18:03 Uhr

Mitglied: 114757
Lösung 114757 26.05.2015 aktualisiert um 13:18:12 Uhr
Goto Top
Nach Zeile 42 folgendes einfügen:
$session = [regex]::Match((quser /Server:$computer),"(?i)$Username\s*([^\s]+)").Groups[1].Value  
logoff $session /Server:$computer
Oder wenn deine Maschine neuer ist kannst du auch Invoke-RDUserLogoff nutzen.

Gruß jodel32
Mitglied: pixel0815
pixel0815 26.05.2015 um 13:18:08 Uhr
Goto Top
Hallo jodel32,

das wars face-smile
Funktioniert super!!
Danke dir !..

Gruß
Heiko