Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapped drives script odd behaviour 2

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
As you start reading this you might think "This is an AD issue! Why is he posting this here?!" Well, you might well be right, but this issue ONLY occurs with Windows 10 clients, though I grant you only then when the script is called from GPO. Anyhoo, please, read on.

We have a logon script, invoked by GPO, which records what drives each user has mapped on each PC (since someone may have a manual mapping on a profile on one PC which doesn't exist on another PC).

The script, which is a batch file (but see below), uses the output from NET USE to create a file in the user's %TEMP% folder, along with a couple of other bits of info (date, time, logon server) then copies that file to a DFS folder.

I noticed t'other day that on Windows 10 it's only recording one drive mapping (and sometimes even just getting "There are no entries in the list"!). If I run the script from the command line, or with a double-click from a shortcut, using the same user account and on the same PC it behaves correctly.

So, I rewrote the script in Powershell (which I feared might take a long time, but probably only took few hours WITH interruptions!)

But I'm getting the same damn result! Usually just capturing their personal 'home' drive mapping (P:), in one case a Z: drive, and one others nothing at all!

On Windows 7 clients there's no problem, it's only happening on Windows 10, and only then when the script is invoked by the GPO.

ALSO, I've re-written the script in Powershell, and I get exactly the same behaviour. The PS script records all the drive mappings when it's run manually with a double-click, but none or only one when the script is invoked by GPO by a Windows 10 client.

What the actual H is going on?!

Should it help, here's the (sanitised-for-the-internet) code:
Code:
@ECHO OFF
::cls
COLOR 9F
SETLOCAL
TITLE Recording drive mappings for %username% on %computername%...
Set ScriptVer=1.06
REM v1.03 = Different method of recording current logon server.
REM v1.04 = Additional NET USE output to %LocalLog%, use TIMEOUT command instead of sleep.exe, use secondary optional parameter for number of seconds to countdown
REM v1.05 = Create mappings file locally then copy up
REM v1.06 = Extra Net Use for bug fixing

Set LocalLog=%temp%\%username%_%computername%_drivemaps.log
Set LocalMappingsFile=%temp%\%username%_%computername%.txt
REM Here we get the path to write the log to as a parameter. The idea is to use the GPO to supply the path so the script
REM so that if the destination path changes we don't need to edit/test/debug the script
Set LogPath=%1
REM But just in case the path hasn't been supplied, here's the hardcoded path
if /i not defined LogPath set LogPath=\\domain.com\logs\Mappings
REM If the path exists, get on with it...
if exist %LogPath% goto MAIN
REM but if it doesn't there's not much point in carrying on!
echo %date% %time% %~nx0 : Can't find %LogPath% to log drive mappings. Quitting.>%LocalLog%

:MAIN
	echo %date% %time% %~nx0 : Recording drive mappings for %username% on %computername%...>%LocalLog%
	echo Logpath=%LogPath%
	
	set count=%2
	if not defined count set count=30
	echo Wait time in second(s) set to %count%
	echo %date% %time% %~nx0 : Seconds to countdown set to %count% >>%LocalLog%
:loop
	:: To give time for drive mappings to complete:
	TITLE Recording drive mappings for %username% on %computername%...%count%
	echo %date% %time% %~nx0 : %count% >>%LocalLog%
	echo %count%
	set /a count=%count%-1
	timeout /t 1 >nul
	if %count% GEQ 1 goto loop
	timeout /t 1 >nul
	
	::@echo on
	echo Recording current drive mappings for %username% on %computername%...
	echo %date% %time% %~nx0 : Writing the Net Use output to %LocalMappingsFile%\%username%_%computername%.txt>>%LocalLog%
	echo %date% %time% %~nx0 : LOGONSERVER=%LOGONSERVER%>>%LocalLog%
	echo %date% %time% %~nx0>%LocalMappingsFile%
	echo LOGONSERVER=%LOGONSERVER%>>%LocalMappingsFile%
	net use | findstr /c:"\\" /c:"There are no entries in the list">>%LocalMappingsFile% 2>>%LocalLog%
	echo %date% %time% %~nx0 : ErrorLevel (0 is good, anything else is bad) = %errorlevel% >>%LocalLog%
	echo ...done!
	echo.
	TITLE Recording drive mappings for %username% on %computername%...DONE!
	net use >>%LocalLog%
	net use >%temp%\netuse.txt
	ECHO %date% %time% %~nx0 : Copying mappings log file to network... >>%LocalLog%
	copy %LocalMappingsFile% %LogPath% /y
	echo %date% %time% %~nx0 : ErrorLevel (0 is good, anything else is bad) = %errorlevel% >>%LocalLog%
	ECHO %date% %time% %~nx0 : Recording drive mappings for %username% on %computername%...DONE! >>%LocalLog%
	
:eof
	::pause

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
My first thought is that the drives haven't mapped yet when this script is running.
Where are the drives getting mapped? Are you looking for persistent local mappings, or are they getting mapped in a GPO? If you are looking for local mappings (where someone has mapped a drive on their local machine, and checked "Reconnect") then the logon script is probably running (since it's a GPO, and therefore gets applied first) before the drives get mapped.

If they are getting mapped in a GPO, you may have your script firing at the wrong time (i.e. firing before the drives are getting mapped).... remember the order that the GPO objects are applied; LSDOU (Local, Site, Domain then OU)

Here's a question; if you run your VBScript manually after the user is logged on and all drives are mapped, does it work properly?



Just my $.02

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg
 
Check this GPO setting

Computer > Administrative Templates > System > Group Policy Settings > Configure Logon Script Delay
 
Thank you, both

@strongm (Hey! How are ya?!)

@gbaughma & strongm
This script includes two required parameters. The first is the path to which the log file should be copied at the end of the script run. The second parameter is the number of seconds to wait before analysing what drives have been mapped. This was included for the very reasons you're both suggesting, i.e. that drives may not yet have mapped when the NET USE command is run to list the drive mappings.

The GPO then includes those two parameters to pass to the script. I've been using a 30 second countdown for years and it's been working fine. When this issue starting occurring I increased it to 60 seconds but with no change in the result. I also watched the temp files that the script creates and opened Windows Explorer to see what happens. I witnessed all the drives being mapped long before the business part of the script runs, so on the face of it this isn't a timing issue.

Standard (personal, departmental, site, and global) drive mappings are all done by GPP. There are a few custom drives which are done by a script, but these are very very rare.

@gbaughma (Neither of these scripts are VB) Both scripts produce the desired result when run manually.

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top