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.
相关问题
- How to Debug/Register a Permanent WMI Event Which
- Django check user group permissions
- How can I do variable substitution in a here-strin
- How to use a default value with parameter sets in
- Does powershell have a method_missing()?
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- C#调用PowerShell的问题
- EscapeDataString having differing behaviour betwee
- Flutter - http.get fails on macos build target: Co
- PowerShell Change owner of files and folders
- Receive share file intents with Flutter
- Command line escaping single quote for PowerShell
- Is there a simple way to pass specific *named* Pow
As of WMF 4:
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.
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.
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.