Question

I need a script to run on Vista Ultimate to share an external drive and assign full control to Everyone. I've got a batch file to create the share using net share, but there doesn't seem to be a way to change the permissions. I reckon this must be possible in PowerShell, but I have no idea where to start.

Was it helpful?

Solution

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.

OTHER TIPS

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.

As of WMF 4:

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

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

The Carbon PowerShell module has two functions that will do this for you: Install-SmbShare and Grant-Permission. I would download it and give it a try.

Install-SmbShare -Name MyShare -Path X:\ -FullAccess 'Everybody' `
                 -Description 'My super-awesome file share!' 
Grant-Permission -Identity Everyone -Permission FullControl -Path X:\

Disclaimer: I am the author and creator of Carbon. I recommend using this module because there are a lot of caveats and potholes to look out for when installing shares and granting permissions. These two function take care of that for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top