Prerequisite code:
Because we are going to be creating one-line scripts, you need a way to set the variable in one line. [because you're interested in creating simple scripts, you need a way to set the variable in one line. ? Dick, is it OK/accurate to add this description text? It seems like we need something here to explain why we want to use the shortcut. Please edit as you see fit.Done] If you simply use the SET /P command on the same code line as the variable, you must operate in a command-shell environment in which the SETLOCAL command [has been run?] with the optional argument ENABLEDELAYEDEXPANSION. 
	Instead of opening a command prompt and running the SETLOCAL ENABLEDELAYEDEXPANSION command every time you want to run a script, you can run the following command to create a OneLinerCmd shortcut on your desktop: 

C:\ResourceKit\Reg.exe add HKCU\Console\onelinercmd\ScreenBufferSize=131072080 REG_DWORD & shortcut.exe -f -t "%systemroot%\system32\cmd.exe" –a "/V:ON" -d %systemdrive%\ -n “%userprofile%\desktop\OneLinerCmd" 

AD Scripting Commands
Active Directory (AD) can provide a wealth of information. Unfortunately, the Microsoft Management Console (MMC) Active Directory Users and Computers snap-in allows only simple list export functions that limit the types of information you can retrieve. However, you can use several resource kit utilities in the AD scripting commands below to mine the wealth of information available in AD.


1. How can I export a list containing all Sales domain computers?

Csvde.exe -f C:\CompList.csv -r "(objectClass=computer)" -d "dc=sales,dc=yourcompany,dc=com" -p subtree

2. How can I search for the LDAP path of a computer in my domain?

(SET /P C=Enter computer name: ) & for /f "tokens=1,2,3,*" %%i in ('CScript //nologo C:\supporttools\search.vbs "LDAP://dc=sales,dc=yourcompany,dc=com" /Q /S:subtree /C:"&(ObjectCategory=computer)(cn=!C!)"') do echo %%l

3. How can I see the detailed Resultant Set of Policies (RSoP)?

(SET /P C=Enter computer name: ) & Gpresult.exe /S !C!

4. How can I find all XP computers in my OU with SP1 installed?

For /f "tokens=1,2,3,4" %%i in ('CScript //nologo C:\supporttools\search.vbs "LDAP://dc=sales,dc=yourcompany,dc=com" /Q /C:"&(ObjectCategory=computer)(operatingsystem=Windows XP Professional)(operatingsystemservicepack=service pack 1)"^| find " objects."') do ECHO %%j

5. How can I get a list of all computers in an OU, including any sub-OUs?

For /f "tokens=3,* delims==," %%i in ('CScript //nologo C:\supporttools\search.vbs "LDAP://dc=sales,dc=yourcompany,dc=com" /S:subtree /Q /C:"&(ObjectCategory=computer)"') do ECHO %%i,%%j>>D:\PCs.csv

6. How can I determine which computer accounts are disabled in my OU?

For /f "tokens=*" %%i in ('C:\w2k3tools\dsquery.exe computer "LDAP://dc=sales,dc=yourcompany,dc=com" -disabled') do @echo %%i 
Note: Dsquery computer syntax on Windows Server 2003 is different. Type "Dsquery user /?" for more info on the syntax. 

7. How can I find all disabled user accounts in my OU?

For /f "tokens=*" %%i in ('C:\w2k3tools\dsquery.exe user "LDAP://dc=sales,dc=yourcompany,dc=com" -disabled') do @echo %%i
Note: Dsquery user syntax on Windows Server 2003 is different. Type "Dsquery user /?" for more info on the syntax. 


Computer Management Scripting Commands
Many of the computer management code examples below let you remotely query and configure systems and eliminate the necessity of physically logging on to every client. Automating your day-to-day computer management tasks can be a major time saver.

8 through 10. How can I determine whether a remote computer is on?

8. With Ping
(SET /P C=Enter computer name: ) & (for /f %%i in ('Ping -n 1 !C!^|Find "Reply"') do @ECHO Online!)||(@ECHO Offline!)

9. With NBTstat
(SET /P C=Enter computer name: ) & (for /f %%i in ('NBTstat -a !C!^|Find "found."') do @ECHO Offline!)||(@ECHO Online!)

10. With Net Use
(SET /P C=Enter computer name: ) & (for /f "tokens=*" %%i in ('@Net Use \\!C!  2^>NUL ^| find "successfully."') do echo Online!)||(ECHO Offline!)

11. How can I compare the time on the local computer with the logon server?

For /f "tokens=*" %%i in ('Net Time \\%COMPUTERNAME% ^| find /V "command"') do @ECHO %%i&For /f "tokens=*" %%i in ('Net Time %LOGONSERVER% ^| find /V /I "command"') do @ECHO %%i

12. How can I compare the time on a remote computer with the logon server?

(SET /P C=Enter computer name: ) & For /f "tokens=*" %%i in ('Net Time \\!C! ^| find /V "command"') do @ECHO %%i&For /f "tokens=*" %%i in ('Net Time %LOGONSERVER% ^| find /V "command"') do @ECHO %%i

13. How can I find all the computers in my Win2K domain that have the word "Sales" in the computer name?

For /f "tokens=1 delims=$" %%i in ('C:\resourcekit\global.exe "Domain Computers" %LOGONSERVER% ^| Find "$" ^| Find /i "SALES"') Do @Echo %%i

14. How can I find all the computers in my NT 4.0 domain that have the word "Sales" in the computer name?

For /f "tokens=1 delims=$" %%i in (' C:\resourcekit\global.exe "Domain Users" %LOGONSERVER% ^| Find "$" ^| Find /i "SALES"') Do @Echo %%i

15. How can I create a shortcut on my desktop to manage a remote computer?

(SET /P C=Enter computer name for shortcut: ) & "Shortcut.exe" -f -t "%SystemRoot%\system32\compmgmt.msc" -a "/computer=!C!" -d "%SystemRoot%\system32" -n "%USERPROFILE%\desktop\!C!-CompMgmt" 

16. How can I check the trust relationship between a computer and its domain?

(SET /P C=Enter computer name: ) & C:\pstools\psexec.exe -c \\!C! C:\supporttools\netdiag.exe /test:trust

17. How can I get system information about a remote computer?

(SET /P C=Enter computer name: ) & C:\pstools\psinfo.exe \\!C!

18. How can I see details of all the running processes on a remote computer?

(SET /P C=Enter computer name: ) & C:\pstools\pslist.exe \\!C!

19. How can I see the last five events in the system log on a remote computer?

(SET /P C=Enter computer name: ) & C:\pstools\psloglist.exe -n 5 system \\!C!

20. How can I determine whether the McAfee virus definitions have been updated in the past 7 days?

(SET /P C=Enter computer name: ) & C:\pstools\psloglist.exe -o mclogevent application -d 7 \\!C!

21. How can I see the past 10 logon events in the System log on a remote computer?

(SET /P C=Enter computer name: ) & C:\pstools\psloglist.exe -i 6009 -n 10 \\!C!

22. How can I see a list of computer accounts that have password ages more than 180 days old?

C:\systools\netpwage.exe /Machines /v /Min:180 /Tabs

23. How can I shut down and restart a remote computer?

(SET /P C=Enter computer name: ) & C:\resourcekit\shutdown.exe \\!C! /R /C

Note: Shutdown.exe on Windows Server 2003 is different. Type "Shutdown /?" for more info on the syntax. 

24. How can I change the username in the logon box back to the original username after I log on to a computer, service it?

(SET /P U=Enter User ID: ) & C:\resourcekit\reg.exe add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v DefaultUserName /d !U!

Note: Reg.exe syntax varies with the Reg.exe version. Type "Reg /?" for more info on the syntax. Reg.exe add with the /f (force switch) may be replaced by Reg.exe update.  

25. How can I see the screensaver settings on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\desktop.vbs /S !C!

26. How can I get a detailed list of drivers on my local computer?

C:\resourcekit\drivers.exe

27. How can I get a detailed list of drivers on a remote computer?

(SET /P C=Enter computer name: ) & C:\pstools\psexec.exe \\!C! /C C:\resourcekit\drivers.exe

28. How can I determine the OS and role of a remote Win2K or NT computer?

(SET /P C=Enter computer name: ) & C:\resourcekit\gettype.exe \\!C!

Note: Gettype syntax varies in Windows Server 2003. Type "Gettype /?" for more info on the syntax and the use of the /S switch.  

29. How can I get the last boot up time and installation date of the OS on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\listos.vbs  /S !C!

30. How can I get the installed printer information, including the default printer, on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\listprinters.vbs /S !C!  

31. How can I view the recovery settings on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\osreconfig.vbs /S !C!  

32. How can I view the pagefile settings on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\pagefile.vbs /L /S !C!  

33. How can I see which user profile contains program menu shortcuts on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\programgroups.vbs /S !C!

34. How can I view the executable paths for processes on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\ps.vbs /S !C!

35. How can I see a quick top-down view of running processes on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\pstop.vbs /S !C!

36. How can I view basic configuration information, including services packs and disk space, on a server?

(SET /P C=Enter computer name: ) & C:\resourcekit\srvinfo.exe \\!C!

37. How can I see a list of hotfixes installed on a remote computer?

(SET /P C=Enter computer name: ) & For /f "tokens=2 delims=[:]" %%i in (' C:\resourcekit\srvinfo.exe -ns \\!C! ^| Findstr "[0-9][0-9]]:"') do @echo %%i

38. How can I view uptime and bluescreen information on a server?

(SET /P C=Enter computer name: ) & C:\resourcekit\uptime.exe /S /A \\!C!

39. How can I view thread information?
(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\thread.vbs /S !C!

40. How can I determine whether the remote procedure call (RPC) hotfix is installed on a remote Win2K computer?

(SET /P C=Enter computer name: ) & C:\resourcekit\reg.exe Query "HKLM\SOFTWARE\Microsoft\Updates\Windows 2000\SP5\KB823980" \\!C! |find /I "- KB823980"&&ECHO SP Installed!||ECHO SP not installed or node not available!

Disk Scripting Commands
You can use scripts to greatly simplify removable and nonremovable disk storage management. As with the computer management scripting commands, many of the disk scripting commands below let you query remote machines for information.

41. How can I determine whether any of the drives labeled C through I on my main file server has the dirty bit set and will run Chkdsk on the next reboot?

For /D %%i in (C D E F G H I) do Chkntfs %%i:

42. How can I prevent the possibility of a large M drive having Chkdsk run on the next reboot?

Chkntfs /X M:

43. How can I make the Chkdsk cancellation timeout period 30 seconds instead of the default 10 seconds to give me more time to stop Chkdsk from running on boot up?

Chkntfs /T:30

44. How can I determine what the Chkdsk timeout period is set for on a server?

Chkntfs /T

45. How can I determine whether physical or logical disk counters are enabled on a remote computer?

(SET /P C=Enter computer name: ) & Diskperf.exe \\!C!

46. How can I get information about the CD-ROM drive on another computer, including determining whether media is present in the drive?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\cdromdrives.vbs /S !C!
OK]

47. How can I see the disk partition information on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\diskpartition.vbs /S !C!

48. How can I get detailed physical drive information on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\drives.vbs /S !C!

49. How can I see the available free space on drives on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\listfreespace.vbs  /S !C!

50. How can I see the total space capacity of drives on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\listspace.vbs  /S !C!

51. How can I view the SCSI controller settings on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\scsicontroller.vbs /S !C!


File, Share, and Printer Scripting Commands
You can use scripts to creating shares, auditing permissions, and even setting up file share resources on a cluster. The code samples below highlight many useful commands for finding files matching certain criteria, doing automated deletions, and determining print driver information.

52. How can I determine whether a share is online?

(SET /P CS=Enter \\servername\sharename: ) & (If Exist !CS! ECHO !CS! online) &  (If Not Exist !CS! ECHO !CS! offline)

53. How can I determine whether any .xls files exist in a folder?

If Exist \\computername\sharename\foldername\*.xls ECHO XLS file(s) exist

54. How can I delete all files in the Temp folder?

Del /Q /S %temp%\*.*

55. How can I delete all files more than 10 days old in the Temp folder?

Forfiles -p%temp% -s -m*.* -d-10 -c"CMD /C DEL /Q /F 0x22@PATH\@FILE0x22"

Note: Forfiles command on Windows Server 2003 is different. Type "Forfiles /?" for more info on the syntax. 

56. How can I delete all empty folders in the Temp folder?

Forfiles -p%temp% -s -m* -c"CMD /C if @ISDIR==TRUE RMDIR 0x22@PATH\@FILE0x22 2>NUL&&echo Deleted @RELPATH\@FILE||Echo Deletion skipped"

Note: Forfiles command on Windows Server 2003 is different. Type "Forfiles /?" for more info on the syntax. 

57. How can I determine how many .xls files are in a directory?

(SET /P TL=Enter target folder location: ) & SET counter=0 & for /f "tokens=1,2 delims=." %%i in ('dir /b !TL!\*.xls') do @set /A counter+=1&@echo ) %%i.%%j

58. How can I change all filenames in a specified folder to lowercase? 

For /f "tokens=*" %%i in ('Dir /l /b /a-d C:\myfolder') Do Ren "C:\myfolder\%%i" "%%i"

59. How can I determine the KB size for a particular file? 
For /f "tokens=4" %%i in ('Dir /a-d /-c C:\WINDOWS\system32\ntoskrnl.exe ^|Find /i "ntoskrnl.exe"') Do (Set /a size=%%i/1024)
Note: The Set /A command has a limitation of 9 digit figures (maximum of 999999999) if you attempt math operations over 9 digits (Numbers are limited to 32-bits of precision) you may get inaccurate results.
 
60. How can I determine how many files are in a folder?

Set Counter=& For /f "tokens=*" %%i in ('Dir /a-d /b %temp%') Do @Set /A Counter+=1 & Echo )%%i

61. How can I create a new shared file resource on my cluster?

(CLUSTER clustername RESOURCE Sharename /Create /Group:"GrpName" /Type:"File Share") & (CLUSTER clustername RESOURCE Sharename /PrivProp Path="R:\MysharedFolder") & (CLUSTER clustername RESOURCE Sharename /PrivProp ShareName="Sharename") & (CLUSTER clustername RESOURCE Sharename /AddDependency:"Disk R:") & (CLUSTER clustername RESOURCE Sharename /Prop Description="Here is my description")

62. How can I locate any open files on a remote computer?

(SET /P C=Enter computer name: ) & C:\pstools\psfile.exe \\!C!

63. How can I view the shares and their permissions settings on a remote computer?

(SET /P C=Enter computer name: ) & C:\resourcekit\srvcheck.exe \\!C!

64. How can I get the properties on a remote shared printer?

CScript //nologo C:\resourcekit\prncfg.vbs -g -b \\servername\printer

65. How can I see only the hidden shares on a remote computer?

(SET /P C=Enter computer name: ) & C:\resourcekit\rmtshare.exe \\!C!|sort|find "$"

Hardware Scripting Commands
Finding out what BIOS version, as well as which network card, video card, or mouse is installed on one or more machines can really help you troubleshoot client driver problems. You can use the commands below to help gather this information.

66. How can I check the BIOS on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\checkbios.vbs /S !C! 

67. How can I see the display adapter properties on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo  C:\resourcekit\listdisplayconfig.vbs /S !C!

68. How can I get the video card information, including the screen resolution, on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\lstdpconinfo.vbs /S !C!  

69. How can I view the pointing device settings on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\pointdev.vbs /S !C!

70. How can I view the processor information on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\processor.vbs /S !C!

71. How can I view the serial port configuration on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\serialport.vbs /S !C!

72. How can I view the audio device configuration on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\sounddevice.vbs /S !C!

73. How can I view tape drive information?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\tapedrive.vbs /S !C!

Networking Scripting Commands
Today’s complex networked environments often can be difficult to troubleshoot without some scripted approaches. In some cases, physically logging onto a user's computer to view the network settings might be the only option where you have no working network interface. In many cases some simple scripting techniques can be used to capture network settings, identify problems, and get things back on track.

74. How can I see the results of the IPConfig /All command on a remote computer?

(SET /P C=Enter computer name: ) & C:\pstools\psexec.exe \\!C! IPConfig /ALL

75. How can I get the media access control (MAC) address on a remote machine?

(SET /P C=Enter computer name: ) & C:\resourcekit\getmac.exe \\!C!

76. How can I see network adapter properties on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\listadapters.vbs /S !C!

77. How can I get network protocol information on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\networkprotocol.vbs /S !C!  

78. How can I view the protocol bindings on a remote computer?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\protocolbinding.vbs /S !C!


Scripting Environment Scripting Commands
With a few simple techniques, you can make your scripting environment easier to work in. The commands below can make your scripting environment easier to create and run your scripts.  

79. How can I get Notepad to save my settings (e.g., font size) between sessions?

C:\resourcekit\reg.exe Add HKCU\Software\Microsoft\Notepad /v fSavePageSettings /t REG_DWORD /d "00000001"
Note: Reg.exe syntax varies with the Reg.exe version. Type "Reg /?" for more info on the syntax. Reg.exe add with the /f (force switch) may be replaced by Reg.exe update.  

80. How can I create a desktop shortcut to the Command Shell online Help files on my Win2K computer?

C:\shortcut.exe -f -t "%SYSTEMROOT%\hh.exe" -d "%SystemRoot%" -a "ms-its:%WINDIR%\Help\windows.chm::/ntcmds.htm" -n "%USERPROFILE%\desktop\W2KCommandLineHelp" 

81. How can I create a desktop shortcut to the Command Shell online Help files on my XP computer?

C:\shortcut.exe -f -t "%windir%\hh.exe" -d "%windir%" -a "ms-its:%windir%\Help\ntcmds.chm::/ntcmds.htm" -n "%USERPROFILE%\desktop\XPCommandLineHelp"

82. How can I find out how long a command or script takes to run?

C:\resourcekit\timethis.exe dir /S /AD /B

Security Scripting Commands
Security is the underpinning of almost everything we do as system administrators. You can use the commands below to script many of the routine security procedures that administrators face every day.

83. How can I connect to another machine with different credentials than I'm logged on with?

(SET /P C=Enter computer name: ) & (SET /P U=Enter user name: ) & NET USE \\!C!\IPC$ * /USER:!U!

84. How can I retrieve the machine SID for a remote computer?

(SET /P C=Enter computer name: ) & C:\Pstools\PsgetSID.exe \\!C!

85. How can I view a list of users who have remote access permissions for a domain?

(SET /P D=Enter Domain name: ) & C:\resourcekit\rasusers.exe %D%

86. How can I send a Net Send message to all members of the local Administrators group while logged onto a computer?

For /f "tokens=1,2 delims=\ " %%i in ('C:\resourcekit\showmbrs.exe \\%computername%\administrators ^| Find /v "Members"') Do Net Send %%j Test Message

Services Scripts
Although you can use the MMC Computer Management snap-in to determine which services are running and to start and stop services, doing so becomes more difficult when you need to query or control multiple nodes. Also, new security concerns require administrators to more closely monitor what services are installed and running. The scripting commands below can empower administrators by letting them quickly gather important service data without having to click through the GUI for each machine.

87. How can I get a list of services on a computer?

(SET /P C=Enter computer name: ) & C:\resourcekit\netsvc.exe \\!C! /List

88. How can I determine whether the Web service is running on a server?

(SET /P C=Enter computer name: ) & C:\resourcekit\netsvc.exe \\!C! W3SVC /query  

89. How can I view a list of stopped services on a remote computer?

(SET /P C=Enter computer name: ) & C:\resourcekit\sclist.exe -s !C!

Users and Groups Scripting Commands
User and group creation and auditing operations can consume much of an enterprise administrator’s time. Fortunately, the code below contains a wealth of user and group-related utilities that are available. 

90. How can I determine how many groups I am in?

Set cntr=0&for /f "tokens=1,2,3,4 delims=[]" %%i in ('C:\joeware\memberof.exe -q -u %USERDOMAIN%\%USERNAME%') do (SET /A cntr+=1) & (ECHO ^) %%l)

91. How can I determine how many groups another user is in?

(SET /P USER=Enter domainname\username: ) & set cntr=0&for /f "tokens=1,2,3,4 delims=[]" %%i in ('C:\joeware\memberof.exe -q -u %USER%') do (SET /A cntr+=1) & (ECHO ^) %%l)

92. How can I tell when a domain user account expires (same domain as the logged on user)?

(SET /P U=Enter user name: ) & C:\joeware\accexp.exe !U! -q -s %LOGONSERVER%

93. How can I determine who is logged on locally to a remote computer?

(SET /P C=Enter computer name: ) & C:\pstools\psloggedon.exe -L \\!C!

94. How can I see a history of the users logged onto a computer?

(SET /P C=Enter computer name: ) & C:\systools\netusers.exe \\!C! /history /local

95. How can I see a list of user accounts that have password ages between 90 and 180 days old?

C:\systools\netpwage.exe /Users /v /Min: 90 /Max:180 /Tabs

96. How can I find out the members of a Local group?

C:\resourcekit\local.exe "groupname" domainname

97. How can I find out the members of a Global group?

C:\resourcekit\global.exe "groupname" domainname

98. How can I tell what OU my user account is in?

C:\joeware\username.exe -Q -format 1

99. How can I view a list of users associated with running processes on a remote computer?

(SET /P C=Enter computer name: ) & C:\resourcekit\pulist.exe \\!C!

100. How can I view the startup folders for all users and in user profiles?

(SET /P C=Enter computer name: ) & CScript //nologo C:\resourcekit\startup.vbs /S !C!

101. How can I view basic user account information including account lockout? 

(SET /P DU=Enter domain\Username: ) & for /f "tokens=1,2 delims=\" %%i in ("%DU%") do CScript //nologo C:\resourcekit\useraccount.vbs /D %%i /N %%j

    Source: geocities.com/yogsotho