Command-Line Utilities
In this section, I'll look at several ways you can manage file, print, and user services from the command line.
Using Shares
Sometimes it's inconvenient to use the Windows GUI to map a drive—this 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? 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 machinemaps:
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 is for the current session only and should not be restored upon logon. This is a feature that I call map persistency—keeping 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
FSUTIL
To 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:
VolumeOrDrive
-
The drive letter or volume name of the disk on which you want to modify a quota. Volume names are tricky to specify because you must do so using the globally unique identifier (GUID), which can be a long string of seemingly random numbers.
warninglevel
-
The amount of space at which warnings will be recorded in the system event log.
hardquota
-
The amount of space at which users will reach their maximum allowed disk space.
username
-
The user to which this quota specification applies.
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 250 MB 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 usage—in other words, to list which users are taking up what amount or portion of space—on drive F:
fsutil quota track F:
To list all users over quota on any volume on the server:
fsutil quota violations
Managing Offline Folders
To 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.
VSSADMIN
The GUI for managing shadow copies is somewhat complete; however, it lacks the ability to specify on which 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.
vssadmin Add ShadowStorage /For=C: /On=D: /MaxSize=150MB
This command specifies that storage for shadow copies (known as an association) of drive C: will be stored on drive D:. 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.
vssadmin Create Shadow /For=E: /AutoRetry=2
This command creates a new shadow copy of drive E:. 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.
vssadmin Delete Shadows /For=C: /Oldest
This command deletes the oldest shadow copy on drive C:. 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.
vssadmin Delete ShadowStorage /For=C: /On=D:
This command deletes the storage space on drive D: that is used to store shadow copies of drive C:. If you leave off the /On switch, all shadow copy storage associations for drive C: will be deleted.
vssadmin Resize ShadowStorage /For=C: /On=D: /MaxSize=150MB
This command modifies the maximum size for a shadow copy storage association between drives C: and D:. 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.
Other useful commands:
-------------------
Thanks,
Paddy
No comments:
Post a Comment