Create a Share Remotely using the WMI Command-Line Tool

To manage Windows remotely through the command line interface, you can can use wmic (comes with windows).
Here’s the syntax to create a Windows File Share on a remote machine using a single line of code. With Windows NT some might remember rmtshare.exe which did the same thing, but crashes with more recent versions of Windows.

wmic /node:%REMOTESERVER% share call create “”, “%DESCRIPTION%”,”%MAX CONNECTIONS (LEAVE BLANK FOR UNLTD)%”, “%SHARENAME%”,”” , “%LOCAL PATH TO FOLDER%”, 0

Example:
wmic /node:SERVER1 share call create "", "User Homedrive for microtom","", "microtom$","" , "D:\Shares\Users\microtom", 0

You can find more information on WMIC here:
http://technet.microsoft.com/en-us/library/bb742610.aspx

2 responses to Create a Share Remotely using the WMI Command-Line Tool

How do you create the share with the Share Permission set to “Read” or “Change”? By default this sets the share permission to “Full Control”. Also can you add any other users or groups besides “Everyone”?

Thanks.

Hey Jack, happy new year!
Generally it is not a very good idea to lock down permissions on a share level. Use the NTFS instead. I never tried to change share level permissions, so I would have to find out first.
If you want to go for the NTFS part you can use xcacls.exe or cacls.exe (Windows built in). That also works remotely (eg cacls \\SERVER1\Share$ /G domain\jack:F /T)

Greetings,
Tom

Leave a Reply