使用新的网络帐户SID的New-SmbShare

时间:2019-10-21 08:46:35

标签: powershell permissions share

我正在尝试使用PowerShell自动化我们的新网络帐户流程,但是在尝试创建新的smbshare时陷入困境。我无法使用网络帐户用户名,因为这将需要同步到远程站点服务器,因此我尝试使用网络帐户SID。

在设置NTFS权限时,使用sid可以使用,但是在尝试创建共享并为帐户提供更改权限时,则不能使用sid。我只是在帐户名和安全性ID之间没有映射完成。当我从脚本中取出-ChangeAccess $($accountSID.SID)时,此变量可以正常工作,并且已开始设置。如果有人对如何使此工作有任何想法,那将是很好的。

$accountSID = Get-ADUser -Identity $GetUniqueDetails.Username

if(Test-Connection -ComputerName $fileServer)
{
    $ShareConnect = New-CimSession -ComputerName $fileServer

    New-Item -ItemType Directory -Path "\\$($fileServer)\Users$\$($GetUniqueDetails.Username)"

    $Acl = Get-Acl -Path "\\$($fileServer)\Users$\$($GetUniqueDetails.Username)"

    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($accountSID.SID,"Modify","ContainerInherit, ObjectInherit", "None","Allow")
    $Acl.SetAccessRule($Ar)

    Set-Acl "\\$($fileServer)\Users$\$($GetUniqueDetails.Username)" $Acl

    $FindShare = (Get-SmbShare -Name 'Users$' -CimSession $ShareConnect).Path

    New-SmbShare -Name "$($GetUniqueDetails.Username)$" -Path "$FindShare\$($GetUniqueDetails.Username)" -FullAccess 'AD\Domain Admins', 'AD\Server Admins' -ChangeAccess $($accountSID.SID) -CimSession $ShareConnect}

0 个答案:

没有答案