Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm updating our local admin script which does not include server 2008 r2.

Because 2008 and Windows 7 have same version Microsoft Windows [Version 6.1.7601] so I can't do a version search.

I have tried these option

systeminfo |findstr /B /C:"OS Name"|find "2008"
if not ERRORLEVEL 1 goto W2008

OR

wmic OS get Caption|find "2008"
if not ERRORLEVEL 1 goto W2008

But both option failes. the script is run from GP and it gets applied to computer

@echo off
setlocal
:: Set full path to logfile:
set logfile=C:\temp\pwd.log
:: Initialise logfile:
date /T >%logfile%
echo Starting pwd.log on %computername% >>%logfile%
:: ##############################################################
:: Set the required passwords here:
set ntw2kadmin=ntwpass
set xpvistaadmin=xppass
set w2k3admin=2003pass
set w2k8admin=P2008pass
:: ##############################################################
:: Exceptions:
if /I "%COMPUTERNAME%"=="PC1" goto SKIP
if /I "%COMPUTERNAME%"=="PC2" goto SKIP
if /I "%COMPUTERNAME%"=="PC3" goto SKIP
:: Set password based on OS version: 
ver|find "4.0" >nul
if not ERRORLEVEL 1 goto NTW2K
ver|find "5.0" >nul
if not ERRORLEVEL 1 goto NTW2K
ver|find "5.1" >nul
if not ERRORLEVEL 1 goto XPVISTA
ver|find "5.2" >nul
if not ERRORLEVEL 1 goto 2K3
ver|find "6.0" >nul|
if not ERRORLEVEL 1 goto XPVISTA
wmic OS get Caption|find "2008"
if not ERRORLEVEL 1 goto W2008

:: Catch any unusual circumstances:
goto XPVISTA
:NTW2K
echo Setting local administrator password for this NT4 or Windows 2000 machine >>%logfile%
net user Administrator %ntw2kadmin% 2>&1 >>%logfile%
goto EOF
:XPVISTA
echo Setting local administrator password for this XP or Vista or Win 7 machine >>%logfile%
net user Administrator %xpvistaadmin% 2>&1 >>%logfile%
goto EOF
:2K3
echo Setting local administrator password for this Windows 2003 Server >>%logfile%
net user Administrator %w2k3admin% 2>&1 >>%logfile%
goto EOF
:W2008
echo Setting local administrator password for this Windows 2008 r2 Server >>%logfile%
net user Administrator %w2k8admin% 2>&1 >>%logfile%
goto EOF
:SKIP
echo Not setting local administrator password for %COMPUTERNAME% >>%logfile%
goto EOF
:EOF
echo setlapwd.bat: exiting >>%logfile%
:: Remove user permissions from the logfile's ACL:
cacls %logfile% /E /R BUILTIN\Users
:: End our local scope:
endlocal

UPDATE: Script gets applied to Windows 2000, Windows XP, Windows 7, Windows Server 2003 but not to Windows 2008 r2

share|improve this question
    
Why aren't you using WMI filters in group policy instead of in the script? –  Tanner May 22 '13 at 14:00
    
this is how company does so i did say we can use gp to do this but i was told to fix this. i try to update the script but 7 and 2008 use same version –  james May 22 '13 at 14:05

2 Answers 2

This worked perfectly for me:

wmic OS get Caption|find "2008"
if not ERRORLEVEL 1 goto W2008

My guess would be the error lies elsewhere in this script. A little more troubleshooting may be in order.

The whole script seems like a mess though. I'd push for a PowerShell script as a replacement, and to maybe use proper WMI filters. Or better yet, enable the following GPO:

Computer Configuration, Windows Settings, Security Options, Account: Administrator account status, Disabled

Local admin profiles aren't really a good idea in the first place.

share|improve this answer
    
wmic OS get Caption|find "2008" if not ERRORLEVEL 1 goto W2008 when i run this on my pc it works fine but becuase gp is getting applied to PC, when pc starts up it just ignores the wmic. if I remove this this works fine for windows 7 and 2008 but the problem is that win7 and win2008 has same version number –  james May 23 '13 at 6:35
    
we can't have powershell script. we have system which are running win 2000 and even 95 –  james May 23 '13 at 6:36
    
@James Holy %*@! Windows 95? In that case I suggest you seek new employment. Seriously. What good is experience in antiquated systems and methods? –  Tanner May 23 '13 at 20:32

Here is the answer. I have used the DSquery to search our ad, if its in server ou then process as server else process as desktop.

@echo off
:: Limit scope:
setlocal
:: Set full path to logfile:
set logfile=C:\tmp\passlog.log
:: Initialise logfile:
date /T >%logfile%
echo Starting passlog.bat on %computername% >>%logfile%
:: ##############################################################
:: Set the required passwords here:
::windows 2003 password
set w2k3admin=pass1
::windows 2008 password
set w2k8admin=Pass1
::windows xp, vista, 7 and 8 password
set desktopadmin=pcpass
:: ##############################################################
:: We need a copy of dsquery.exe on the local machine:
echo check dsquery file... >>%logfile%
if not exist %windir%\system32\dsquery.exe copy "\\shared\location\scripts\dsquery.exe" %windir%\system32\dsquery.exe
echo dsquery filed checked... >>%logfile%
:: Are we ignoreOU?
call dsquery computer -name %computername% | findstr /i "OU=ignoreOU"
if not ERRORLEVEL 1 goto ignoreOU
:: Are we a server?
call dsquery computer -name %computername% | findstr /i "OU=Servers"
if not ERRORLEVEL 1 goto server
:: Are we a DC?
call dsquery computer -name %computername% | findstr /i /C:"OU=Domain Controllers"
if not ERRORLEVEL 1 set goto server
::
goto desktop
:server
    ver|find "6.1" >nul
        if not ERRORLEVEL 1 goto 2k8
    ver|find "5.2" >nul
        if not ERRORLEVEL 1 goto 2k3
:2k8
    echo Setting local administrator password for windows server 2008... >>%logfile%
    net user Administrator %w2k8admin% 2>&1 >>%logfile%
    goto EOF
:2k3
    echo Setting local administrator password for windows server 2003... >>%logfile%
    net user Administrator %w2k3admin% 2>&1 >>%logfile%
    goto eof
:desktop
    echo Setting local administrator password for desktop/laptop... >>%logfile%
    net user Administrator %desktopadmin% 2>&1 >>%logfile%
    goto eof
:ignoreOU
    echo Not setting local administrator password for this ignoreOU server... >>%logfile%
    goto eof
:eof
echo passlog.bat: exiting >>%logfile%
:: Remove user permissions from the logfile's ACL:
cacls %logfile% /E /R BUILTIN\Users
:: End our local scope:
endlocal
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.