Sharing a folder and setting permissions in PowerShell Sharing a folder and setting permissions in PowerShell powershell powershell

Sharing a folder and setting permissions in PowerShell


As of WMF 4:

New-SmbShare –Name ShareName –Path C:\LocalFolder –FullAccess Username

http://technet.microsoft.com/en-us/library/jj635722.aspx


In case you're searching for an answer to this question, but you're running Windows 7 (instead of Vista), as I was, you might be interested to know that permissions can be set in the NET SHARE command, now, directly.

For instance,

NET SHARE Movies=M:\Movies /GRANT:Everyone`,READ

will create a share and give Everyone read-only permissions to it.

Instead of READ, you can use CHANGE or FULL as well.


Two answers.

In PowerShell, the Get-ACL cmdlet will retrieve the existing permissions. You then modify those using .NET commands, and run Set-ACL to apply it back to the folder - the help for these two cmdlets includes examples, and you can download the book examples from www.sapienpress.com for "Windows PowerShell: TFM" = the book also contains explicit examples.

However, it is not worth your time. Practically speaking, file ACLs are a royal pain to deal with and incredibly complicated. Microsoft has already written lovely tools to do this, like Cacls, and it's far easier just to use those.

Now that's all FILE permissions - you may also be interested in changing the permissions on the SHARE itself. The tool for that is SUBINACL, and you can download it from Microsoft. See also http://cwashington.netreach.net/depo/view.asp?Index=1127&ScriptType=vbscript.