[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Find a user where all in the network he is logged in.Not at present but already has logged in some day.

Hi,

Find a user where all in the network he is logged in.Not at present but already has logged in some day.

A way for a script to query the profiles in each machine .All the machines in the network or machine names in the txt file.

Regards
SHarath
0
bsharath
Asked:
bsharath
1 Solution
 
Farhan KaziSystems EngineerCommented:
:: ================
:: READ THIS FIRST
:: ================
:: * To run this script you must have domain administrators rights.
:: * This script require "Computers.txt" file from where it will pick computer names.
:: * Successful run will generate "FoundProfile.txt"
:: * USAGE: ScriptName.cmd "UserName"
:: * Copy and Paste following script into notepad and save it with any name having .cmd extension.
:: SCRIPT START

@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET UserName=%1
IF [%UserName%]==[] (ECHO USAGE: ScriptName.cmd ^<"UserName"^>&ECHO. &GOTO :EndScript)
IF NOT EXIST Computers.txt GOTO ShowErr
FOR %%R IN (Computers.txt) Do IF %%~zR EQU 0 GOTO ShowErr
IF EXIST FoundProfile.txt DEL /F /Q FoundProfile.txt
FOR /F %%c IN ('Type Computers.txt') Do (
    Echo Processing: %%c
      PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
      IF NOT ErrorLevel 1 (
            DIR /B \\%%c\C$\"Documents and Settings" |FIND /I !UserName! >NUL
            IF NOT ErrorLevel 1 (ECHO !UserName! users profile FOUND on: %%c >>FoundProfile.txt
            )ELSE (ECHO !UserName! users profile NOT found on: %%c >>FoundProfile.txt)
      )ELSE (ECHO Unable to connect '%%c')
)      
ECHO.
ECHO --------------
ECHO Search Results
ECHO --------------
TYPE FoundProfile.txt
ECHO.
GOTO EndScript
:ShowErr
Echo "Computers.txt" file does not exist or file is empty!
:EndScript
ENDLOCAL
:: *** SCRIPT END ***
0
 
bsharathAuthor Commented:
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now