3.13. Command Line UtilitiesIn this section, I'll look at several ways you can manage file, print, and user services from the command line. 3.13.1. Using SharesSometimes it's inconvenient to use the Windows GUI to map a drivethis is a problem particularly in logon scripts. How do you use a batch file to tell the mouse pointer to move over to My Network Places? Instead, there's a better way. The net use command enables you to map any drive to any server on your network, and in some cases, outside networks, too. The syntax is: net use drive \\server\share Here are some common examples that you should find useful. To map drive H to Lisa Johnson's home directory on server MERCURY: net use H: \\mercury\users\lmjohnson To map the first available drive letter to the same directory: net use * \\mercury\users\lmjohnson Sometimes you might need to connect to a share on a domain that isn't trusted by your home domain. If you have an account on that domain, you can use it to connect, like so: net use H: \\foreignmachine\sharename /user:foreigndomain\username (If you need to use a password, you'll be prompted for it.) If you need to terminate a connection or map to a server, use the /d switch: net use \\mercury\users\lmjohnson /d To disconnect all drive mappings on the local machine maps: net use * /d To connect to a foreign machine (152.1.171.133 in this example) over the Internet or an intranet without relying on name resolution: net use H: \\152.1.171.133\c$ You also can use a different account with the IP address: net use H: \\152.1.171.133\c$ /user:hasselltech\hassell And you can specify that this mapping be for the current session only and not be restored upon logon. This is a feature that I call map persistencykeeping the same mappings across login sessions, a big timesaver for your users. To do so: net use H: \\152.1.171.133\c$ /persistent:no 3.13.2. FSUTILTo set up default quotas and modify them using the command line, type the following at the prompt: fsutil quota modify [VolumeOrDrive] [warninglevel] [hardquota] [username] replacing the text in brackets with the appropriate information as specified in the following list:
Using fsutil.exe, you can create scripts to automatically set quota entries upon new-user creation to work around the limitation of assigning quotas to groups, as described earlier in this chapter. fsutil.exe can help you access functionality more quickly and efficiently than you can by using the GUI interface. The following examples, designed to run from a command line, illustrate the quota functionality available through fsutil.exe. To disable quota support on drive C: fsutil quota disable C: To enable quota support on drive E: fsutil quota enforce E: To set a 250MB quota for Lisa Johnson (user ID lmjohnson) on drive C: fsutil quota modify C: 250000000 lmjohnson To list the current quotas set on drive D: fsutil quota query D: To track the disk usagein other words, to list which users are taking up what amount or portion of spaceon drive F: fsutil quota track F: To list all users over quota on any volume on the server: fsutil quota violations 3.13.3. ABECMDABECMD is the command-line counterpart to the access-based enumeration add-in to Windows Server 2003. You can enable access on a specific shared folder, on all shared folders on the current computer, or on shared folders on another machine. The syntax works like this:
3.13.4. Managing Offline FoldersTo make a share's contents available offline from the command line, at a prompt type: net share nameofshare /CACHE:[manual | documents | programs | none] /CACHE:manual enables manual client caching of programs and documents from this share. /CACHE: documents enables automatic caching of documents from this share /CACHE:programs enables automatic caching of documents and programs (distinguished by their file extension) from this share. /CACHE:none disables caching from this share. 3.13.5. VSSADMINThe GUI for managing shadow copies is somewhat complete; however, it lacks the ability to specify on what disk or volume shadow copies are stored. Also, an administrator cannot delete specific shadow copy files using the GUI. This might be needed if a user creates an incorrect version of a file, then leaves and another worker comes back the next day. An administrator might need to delete the previous version as soon as possible so that the new user doesn't inadvertently work from the incorrect version. The vssadmin.exe command-line utility was created to offer administrators the ability to control these factors. I'll now walk through several examples. This command specifies that storage for shadow copies (known as an association) of drive C: will be stored on drive D:: vssadmin Add ShadowStorage /For=C: /On=D: /MaxSize=150MB The maximum space the association can occupy on the shadow copy storage volume is 150 MB. If a value is not specified, there is no limit to the amount of space shadow copies can use. Shadow copies require at least 100 MB of space, and you can specify the maximum amount in KB, MB, GB, TB, PB, and EB, although it's assumed if you don't use a suffix, the value is in bytes. This command creates a new shadow copy of drive E:: vssadmin Create Shadow /For=E: /AutoRetry=2 The /AutoRetry switch dictates that if another process is attempting to make shadow copies at the same time vssadmin is attempting to make them, the utility will keep trying for two minutes. This command deletes the oldest shadow copy on drive C:: vssadmin Delete Shadows /For=C: /Oldest You can use the /all switch to instead delete all shadow copies that can be deleted. You also can specify a specific shadow copy to delete by using /Shadow=ID, where ID is the hexadecimal number you obtain through the List Shadows command, covered later in this section. This command deletes the storage space on drive D: that is used to store shadow copies of drive C:: vssadmin Delete ShadowStorage /For=C: /On=D: If you leave off the /On switch, all shadow copy storage associations for drive C: will be deleted. This command modifies the maximum size for a shadow-copy storage association between drives C: and D:: vssadmin Resize ShadowStorage /For=C: /On=D: /MaxSize=150MB Again, the maximum size has to be 100 MB or more. If you decrease the maximum size, older shadow copies can be deleted to make room for more recent shadow copies. Here are some other useful commands: This command lists registered volume shadow copy providers: vssadmin List Providers This command lists existing volume shadow copies and their ID numbers, for use with the Delete Shadows command: vssadmin List Shadows This command shows the disks that are eligible to support shadow copy functionality: vssadmin List ShadowStorage 3.13.6. NTBACKUPTo back up to a file or tape from the command line, use: ntbackup backup [systemstate] "@FileName.bks"/J "JobName" [/P "PoolName"] [/G "GUIDName"][/T "TapeName"] [/N "MediaName"] [/F "FileName"][/D "SetDescription"] /DS "ServerName"][/IS "ServerName"] [/A] [/V:yes | no] [/R:yes | no][/L:f | s | n] /M "BackupType"][/RS:yes | no] [/HC:on | off] [/SNAP:on | off] Table 3-3 explains the various options.
Using NTBACKUP from the command line has two important limitations. One, you cannot restore files, and two, you cannot back up system state data on a remote computer.
Switches /V, /R, /L, /M, /RS, and /HC default to the setting in the GUI version of Backup unless you explicitly set them on the command line. 3.13.6.1. Sample scenariosIn this section, I'll offer some possibilities for automating backups using the command line. You should find that it's easy to modify the examples provided here (if they don't fit your needs as-is) to extend their capabilities. The first example executes a normal backup named "Nightly" of the network share \\winsrv-1\c$. This example selects media from the Tapes pool and names the tape "Nightly NTBACKUP 1." The description of the backup job is "Standard evening backup." A verification pass is done, access to the tape is open to all, and only a summary log will be produced, Remote Storage data is not backed up, and hardware compression will be used. ntbackup backup \\winsrv-1\c$ /m normal /j "Nightly" /p "Tapes" /n "Nightly NTBACKUP 1" /d "Standard evening backup" /v:yes /r:no /l:s /rs:no /hc:on The next example starts a copy backup named "Lunchtime" of the E: drive on the server itself. The backed-up files and folders are appended to the tape named "Nightly NTBACKUP 1." Because no other switches are present, the default settings in the GUI version of Backup are used. ntbackup backup e:\ /j "Lunchtime" /a /t "Nightly NTBACKUP 1" /m copy The following example performs a backup using the GUI Backup program's current setting. The program looks at the file weekend-backup.bks, located in the C:\Program Files\Windows NT\ntbackup\data\ directory, to select the particular data to back up. The backup job is named "Weekend" and it overwrites the tape named "Weekend NTBACKUP 1" with the new name "Weekend NTBACKUP 2." It also includes System Statesystem state information. ntbackup backup systemstate "@C:\Program Files\Windows NT\ntbackup\data\ weekend-backup.bks" /j "Weekend" /t "Weekend NTBACKUP 1" /n "Weekend NTBACKUP 2" The final example backs up a remote share to a file named backup.bkf using the Backup program's default values for the backup type, verification setting, logging level, hardware compression, and access restrictions: ntbackup backup \\win-srv2\acctg$ /j "To File on MWF" /f "E:\backup.bkf" When running this command again, if you want to append another backup to the existing file, simply add the /a switch as shown. Otherwise, you will overwrite the existing file automatically. ntbackup backup \\ntsrv-5\sales-execs$ /j "To File on TH" /f "E:\ backup.bkf" /a 3.13.7. CIPHERYou can control encryption from the command line using the CIPHER utility, located in %SystemRoot%\System32:
You also can decrypt files and folders quickly from the command line if you are the recovery agent for those folders or the user who originally encrypted the objects. Use the cipher command with the /u and /a switches. For example, to decrypt a file called man_ch3r3.doc, issue the following command: cipher /u /a man_ch3r3.doc Table 3-4 lists other command-line arguments for the CIPHER utility.
3.13.8. Printing from the Command LineYou can accomplish some of the more basic printing functions through the command line, which makes it easier for an administrator to script printer configuration and mapping for logon/logoff scripts and other batch automation procedures. The following example commands perform a variety of printing functions:
|