Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Remote GPResult Batch File

Posted on 2012-08-27
4
Medium Priority
?
2,171 Views
Last Modified: 2012-08-27
I have a batch file that contains:

gpresult /s %1 /user %2 /h report.htm /f
report.htm

How can I change this so that /user %2 is the current logged in user of the remote machine?
0
Comment
Question by:Joseph Moody
  • 2
4 Comments
 
LVL 13

Expert Comment

by:xDUCKx
ID: 38336733
Windows XP:

Domain\%username%

Windows 7

%whoami%
0
 
LVL 22

Author Comment

by:Joseph Moody
ID: 38336776
The %username% inputs the current logged in user of my machine. How can I have it give me the current logged in user of the remote machine?
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 38336887
It's not that easy, because there may be several accounts logged on on the remote machine. Download Microsoft's PsLoggedOn (http://technet.microsoft.com/en-us/sysinternals/bb897545.aspx) and put it into the same folder as the script below. The script will query for logged on users on the remote machine, and give you a menu to pick form if more than user is logged on. As before, you can still pass it the user name in the command line as second argument:
@echo off
setlocal enabledelayedexpansion
set ReportFile=report.html
if "%~1"=="" (
	echo Syntax: %~nx0 Computer [Username]
	goto :eof
)
set Computer=%~1
if not "%~2"=="" (
	set User=%~2
	goto GPResult
)
set User=
set /a UserCount = 0
for /f "skip=1" %%a in ('psloggedon.exe -x -l -accepteula \\%Computer% 2^>NUL') do (
	set /a UserCount += 1
	set User[!UserCount!]=%%~a
)
if "%UserCount%"=="0" (
	echo No users sessions found on %Computer%.
	goto :eof
)
if "%UserCount%"=="1" (
	set User=%User[1]%
	goto GPResult
)
set User=
echo More than one user is logged on; please choose one:
for /l %%i in (1, 1, %UserCount%) do (
	echo %%i	!User[%%i]!
)
set /p ID=^>
set User=!User[%ID%]!
if "%User%"=="" goto :eof
:GPResult
gpresult.exe /s %Computer% /user %User% /h "%ReportFile%" /f
start "" "%ReportFile%"

Open in new window

0
 
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 38336924
If I could give you 50,000 points, I would! This is awesome!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question