[英]Run Net Share command in powershell script
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. 我尝试使用net share命令在powershell中共享一个文件夹,我不能使用组或用户名来获得共享权限,因为这个脚本将在具有不同操作系统语言的系统上使用,因此我使用组/用户SID来设置分享权限。
Here is my script, my function work great outside of command. 这是我的脚本,我的功能在命令之外很棒。 But my function dont work in "NET SHARE" cmd.
但我的功能不适用于“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
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: 但是,如果您使用的是Windows 8或更高版本的Windows Server 2012或更高版本,则可以使用
Set-SmbShare
和Grant-SmbShareAccess
cmdlet:
http://technet.microsoft.com/en-us/library/jj635727 http://technet.microsoft.com/en-us/library/jj635727
http://technet.microsoft.com/en-us/library/jj635705 http://technet.microsoft.com/en-us/library/jj635705
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.