NTFS Permissions – Via “Net Share”

Background

Have a need to create a few shares and grant permissions to them.

We will use NetShare to automate the Share Creation and permissioning.

 

Use NetShare To Create And Grant Permissions

Using NetShare grant permissions to Share SQLErrorLog

Code


set "_share=SQLErrorLog"
set "_folder=M:\Microsoft\SQLServer\SQLErrorLog"

set "_user_everyone=everyone"


set "_networkUserQA=LAB\DBQA$
set "_permission_read=Read"
set "_permission_full=Full"
set "_permission_change=Change"

if not exist %_folder% mkdir %_folder%

net share %_share%=%_folder% /GRANT:"%_user_everyone%",%_permission_read% /GRANT:"%_networkUserQA%",%_permission_change% 

Explanation

In the sample above, we did the following:

  1. Created a new network share by the name SQLErrorLog
  2. It is sourcing M:\Microsoft\SQLServer\SQLErrorLog
  3. We are granting the following permissions
    • Read to everyone; that is all local users
    • Change ( Read and Write) to the Network Service Account on machine DBQA.  Btw, the Domain name is LAB

Review Share Permissions

Code


net share SQLErrorLog

Output

netshare-qa

 

Use NetShare to drop Share

Code


set "_share=SQLErrorLog"
set "_folder=M:\Microsoft\SQLServer\SQLErrorLog"

if not exist %_folder% mkdir %_folder%

net share %SQLErrorLog%

if %errorlevel% EQU 0 Echo Deleting Share %_share% ... | net share %_share% /DELETE

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s