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:
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]
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]