Skip navigation

101 One-line “How Can I?” Scripting Commands

Get into scripting

Downloads
41198.zip

I recently attended a Windows Server 2003 training seminar. During our class discussion, the instructor mentioned several operations, a few of which were scriptable. Out of the approximately 20 students in the room, all of whom were experienced systems administrators, only a few of us had any scripting experience. The others wanted to hear more after they learned about the possibilities. As a scripting evangelist, I often discover that once systems administrators get bitten by the scripting bug, they're hooked for life. Scripts let you accurately and quickly perform repetitive functions. So, for example, knowing how to write a script to capture information from several remote nodes and create meaningful reports can make the task fun instead of drudgery.

For many systems administrators, the first question is, How do I get started? For the beginner, the difference between scripting 1 line of code to display the words "Hello World" on screen and scripting 200 lines of code to perform a meaningful task is a quantum leap. If you're new to scripting, you probably just want to know what scripting can do for you. Often, the best approach is to start by running some simple but useful commands. Then, after you master the basics, you can turn to more advanced resources, including books about scripting, to enhance your skills.

I've created 101 "how to" scripting commands to answer 101 of the most common "How can I?" questions, and I provide some sample script code to get you started. These examples are designed to introduce you to the power of shell scripting, get you hooked on the potential of scripting for making your job easier, and provide you with greater safety, security, and accuracy when performing your daily tasks.

Getting the Scripting Commands to Work in Your Environment
Before you jump in, you need to ensure that the scripting commands presented in this article will work in your environment. Be aware that I tested these commands on Windows XP Professional Edition Service Pack 1 (SP1) and Windows 2000 SP3. I've provided the following prerequisites and tips to help you get started. Let's first consider the following prerequisites:

  • Install the utilities that the code requires. For a list of these resources, see Web Table 1, http://www.winnetmag.com/windowsscripting, InstantDoc ID 41198, or refer to the path name hints I've used that apply to my test machine. Most of the tools are from the Microsoft Windows 2000 Resource Kit and Win2K Support Tools or are built-in commands, but a few are third-party freeware tools.
  • Configure the code to include the path to the utilities you installed.
  • Configure the Lightweight Directory Access Protocol (LDAP) path or other required information if the script doesn't prompt you for user input.
  • Next, let's consider a few tips that can make running the scripts easier:

  • Many of the scripts use the Set /P command to ask the user for input. If you'd rather use hard-coded server names or usernames, remove "(SET /P C=Enter computer name: ) &" and replace the !C! or !U! variable with the hard-coded computer name, username, or other information for which the script prompts you.
  • You can create a shortcut that in turn creates an environment in which to run the scripts. Typically, when you add code to a script, you set a variable, such as a computer name, in one line of code and use that variable in another line of code later in the script, such as you see in this example:
(SET /P C=Enter computer name: )
ECHO %C%

However, because we're going to create one-line scripts, you need a way to set the variable in one line. 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 one-line 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 %system
  drive%\ -n "%userprofile%  desktop\OneLiner Cmd"

(Although this command and the other one-line commands in this article wrap to multiple lines, lines of code that you cut and paste from this article might not work properly until you "unwrap" them to one line. You can download the code in the form of a properly formatted text file from the Windows Scripting Solutions Web site.) The code uses the Cmd /V:ON command to launch a script environment that achieves the same result as using Setlocal. Note that the shortcut that the script creates will change the screen buffer size to give you a larger scrolling window for your command output.

  • Copy and paste the scripts into a command-shell window. Highlight the code you want to run, then right-click in the command window to paste in the code. If you can't paste in code, open the Command Prompt Properties window, select the Options tab, and ensure that the QuickEdit and Insert modes are enabled by selecting the associated check boxes.
  • The commands and tools included in the scripts in this article offer many more options than I can describe. If you encounter differences running these commands in Windows 2003 or if you just want to see all the options that might be useful in your environment, type
Command Name /?

Also, multiple versions might exist for some tools, such as reg.exe and gpresult.exe. Check to be sure that the version of the utility you're using supports the syntax presented in this article.

  • Several of the scripts that run .vbs files use CScript to run those files. When you call a .vbs file with CScript, you must provide the full path to the .vbs file.
  • Carefully test the scripts in a development environment before you use them in production. Notice that the scripts in this article are primarily data acquisition scripts and, with a few exceptions of some temporary file-cleanup scripts, the scripts perform no changes to your files or groups.
  • All scripts are limited to the authority of the logged-on user who's executing them. You won't be able to run most of the scripts without Administrator group membership on local or remote servers or clients.
  • As the demand for one-to-one correspondence between GUI and scripted operations has grown, Microsoft has added scripting tools to the OS. In some cases, these tools are new (e.g., dsquery.exe), and in other cases, these tools came from the Win2K resource kit, Microsoft Windows NT Server 4.0 Resource Kit, or Win2K Support Tools (e.g., gpresult.exe). If you plan to run these scripts in Windows 2003, check to be sure that the tool isn't already installed before you add any resource kit tools.

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:
  ) &amp For /f "tokens=1,2,3,*"
  %i in ('CScript //nologo
  C:\supporttools\search.vbs
  "LDAP://dc=sales,dc=your
  company,dc=com" /Q /S:subtree
  /C:"&amp(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:
  ) &amp gpresult.exe /S !C!

4. How can I find all XP computers in my organizational unit (OU) that have SP1 installed?

For /f "tokens=1,2,3,4" %i in
  ('CScript " //nologo
  C:\supporttools\search.vbs"
  "LDAP://dc=sales,dc=your
  company,dc=com" /Q /C:"&amp
  (ObjectCategory=computer)
  (operatingsystem=Windows XP
  Professional)(operating
  systemservicepack=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=your company,dc=com" /S:subtree /Q /C:"&amp(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

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=your
  company,dc=com" -disabled')
  do @ECHO %i

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. How can I determine whether a remote computer is on with Ping?

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

9. How can I determine whether a remote computer is on with NBTstat?

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

10. How can I determine whether a remote computer is on with Net Use?

(SET /P C=Enter computer name:
  ) &amp (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&ampFor /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:
  ) &amp For /f "tokens=*" %i in
  ('Net Time \\!C! ^| find /V
  "command"') do @ECHO %i&ampFor
  /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" %LOGON
  SERVER% ^| 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: ) &amp "shortcut
  .exe" -f -t "%SystemRoot%
  \system32\compmgmt.msc" -a
  "/computer=!C!" -d "%System
  Root%\system32" -n "%USER
  PROFILE%\desktop
  \!C!-CompMgmt"

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

(SET /P C=Enter computer name:
  ) &amp 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:
  ) &amp 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:
  ) &amp 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:
  ) &amp 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:
  ) &amp 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:
  ) &amp C:\resourcekit\shutdown.exe
  \\!C! /R /C

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

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

Note: Reg.exe syntax varies with the reg.exe version. Type

Reg /?

for more information about the syntax. Reg.exe update might have replaced reg.exe /f.

25. How can I see the screen saver 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:
  ) &amp 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:
  ) &amp C:\resourcekit\gettype
  .exe \\!C!

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:
  ) &amp 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:
  ) &amp 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:
  ) &amp 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:
  ) &amp 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:
  ) &amp 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 service 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 blue screen 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!

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

(SET /P C=Enter computer name:
  ) &amp 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!

Converting the Scripting Commands into Batch Scripts
Now that I've introduced you to the scripting commands, you'll want to consider the following notes and advice when converting these commands for use in your own .bat file scripts:

  1. To convert the one-line commands into multiline batch scripts, copy the one line of code into a text file and rename the file with a .bat extension.
  2. Put the Setlocal Enabledelayedexpansion command at the top of your script before other code. Commands that are linked by one ampersand (&) should each be put on one line and the ampersands removed.
  3. The For command uses slightly different syntax when run in a .bat file. Replace any single percent signs (%) with double percent signs (e.g., replace %i with %%i) if you're saving the code into a .bat file. If you're copying and pasting code into the command shell, retain the single percent signs.
  4. You can execute .bat file scripts by double-clicking them or dragging them into a command-shell window and executing them from there by pressing Enter. If you want the command-shell window to stay open until you hit another key after you double-click your .bat script, add the Pause command to the bottom of your script.
  5. For the start of a 10-part article series with homework that will help you get up to speed on scripting and help you get more out of your converted one-line scripting commands, see "Shell Scripting 101, Lesson 1," http://www.winnetmag.com/windowsscripting, InstantDoc ID 16355.
  6. Get Timothy Hill's Windows NT Shell Scripting (Que, 1998), which is the best reference book for built-in Windows commands and resource kit utilities. Some command syntax might have changed on newer resource kit utility versions, but this book is still quite valuable.

File, Share, and Printer Scripting Commands
You can use scripts to create shares, audit permissions, and even set 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: )
&amp (If Exist !CS! ECHO !CS! online) &amp 
(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 2003 is different. Type

Forfiles /?

for more information about 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 2003 is different. Type

Forfiles /?

for more information about 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 kilobyte 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 nine-digit figures (maximum of 999999999). If you attempt math operations involving more than nine digits (numbers are limited to 32 bits of precision), you might 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:\resourcekitprncfg.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 on to a user's computer to view the network settings might be the only option for which you have no working network interface. In many cases, you can use some simple scripting techniques 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:\resourcekitgetmac.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 in.

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

C:\resourcekit\reg.exe Add HKCU\SoftwareMicrosoft\Notepad /v fSavePageSettings 
/t REG_DWORD /d "00000001"

Note: Reg.exe syntax varies with the reg.exe version. Type

Reg /?

for more information about the syntax. Reg.exe update might have replaced reg.exe /f.

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 systems 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 by using 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 on to 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 snap-in 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'm 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's logged on locally to a remote computer?

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

94. How can I see a history of the users logged on to 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
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish