Creare share in powershell si asignare drepturi(Scripting)

Configurare noua (How To)

Situatie

Dorim sa cream un share si sa dam drepturi tuturor.

Solutie

Deschidem powershel-ul cu drepturi de admin.

Dupa care rulam urmatorul Script.

function createSmbShare($localPath,$fullAccessAccounts){
    $ErrorActionPreference='stop'
    try{
        # First, create SMB Share
        $smbShareName=split-path $localPath -leaf
        New-SmbShare -Name $smbShareName -Path $localPath -FullAccess $fullAccessAccounts
        # Second, set NTFS permissions
        $acl = Get-ACL $localPath
        foreach($account in $fullAccessAccounts){
            $allowFullAccesss=New-Object System.Security.AccessControl.FileSystemAccessRule($account,"Full","Allow")
            $acl.AddAccessRule($allowFullAccesss)
            }
        Set-Acl $localPath $acl
        write-host "\\$env:computername\$smbShareName has been created with full access granted to these users $fullAccessAccounts"
        }
    catch{
        write-warning $Error[0].Exception.Message
        return $false
        }
}
createSmbShare $localPath $fullAccessAccounts
Folder-ul trebuie creat manual, scriptul il share-uieste si ofera permisiuni.

Tip solutie

Permanent

Voteaza

(13 din 41 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?