Creating Remote Shares in Windows from the Command Line

No doubt the first question one would have may well be, “Why in the world would you want to do such a thing?”  Well, if you have a domain and prefer to use the command line, then this could help you. Obviously, there’s little need for this type of thing on a standalone computer.
So, how do we do it?
You’ll need a copy of rmtshare.exe — it’s in the Windows NT Resource Kit, but Microsoft has also placed it in the public domain. You can download a copy of it from Microsoft’s FTP site at:
Place the file in a folder then run it to extract a readme.txt file and the executable itself.
No better way than to demonstrate:
Let’s say you have a server called webserver01 and it has a directory called D:\Logs from which you wish to create a share. Let’s also say that we want the share to be readable only to a single domain user or group. We’ll call it “MYDOMAIN\LogReaders”.
Easy enough:
rmtshare \\webserver01\logs=d:\logs /REMARK:"Log files" /GRANT "MYDOMAIN\LogReaders":r
Very nice.
What if you have, say, 10 or even 1000 servers you want to do exactly the same thing on in your domain?
for %f in (
) do (
rmtshare \\%f\logs=d:\logs /REMARK:"IIS Logs" /GRANT "MYDOMAIN\LogReaders":r
One could also, if desired, just feed the for command a file that has all of the server names in it — one server per line — to accomplish the same thing in even fewer lines:
for /f "usebackq tokens=1" %f in (
`type c:\path\to\serverlist.txt`
) do (
rmtshare \\%f\logs=d:\logs /REMARK:"IIS Logs" /GRANT "MYDOMAIN\LogReaders":r
Or even one line, if desired:
for /f "usebackq tokens=1" %f in (`type c:\path\to\serverlist.txt`) do ( rmtshare \\%f\logs=d:\logs /REMARK:"IIS Logs" /GRANT "MYDOMAIN\LogReaders":r )
I love the command line.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.