3

I try to share a folder in powershell with net share command, i can't use group or user name for share permission because this script will be used on the systems with different os languages, for this reason i use group/user SID to set up share permissions.

Here is my script, my function work great outside of command. But my function dont work in "NET SHARE" cmd.

function Get-GroupName {
param ($SID)

$objSID = New-Object System.Security.Principal.SecurityIdentifier($sid)
$objUser = $objSID.Translate([System.Security.Principal.NTAccount])
$objUser.Value
}

# Share Folder + Set Share Permission SID Based
cmd /c net share MSI=C:\MSI /GRANT:(Get-GroupName -SID 'S-1-1-0'),READ 

1 Answer 1

2

This will work:

cmd /c $( "net share MSI=C:\MSI /GRANT:""$(Get-GroupName -SID 'S-1-1-0')"",READ" )

But if you're on Windows 8 or newer, Windows Server 2012 or newer you can use the Set-SmbShare and Grant-SmbShareAccess cmdlets instead:

http://technet.microsoft.com/en-us/library/jj635727

http://technet.microsoft.com/en-us/library/jj635705

Sign up to request clarification or add additional context in comments.

5 Comments

thank you very much, it work great ! Do you know where i can get more information about how i must use my commands in "string".
You're welcome. I think this link will be helpful.
I would gladly help but I think that for readability and for the community it would be better to create a new question so I (and other people) can answer it.
And by the way I think I have the answer.
Ok i will create a new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.