Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Setting Permissions on network Folder

$
0
0

I am creating an "H:" for users on a file server.  The code changes so other settings aswell and they are working.  I have the code to create the folder and I am trying to figure out how to set the permission on the folder and I am running into some issues.  Here is the code:

    $EmployeeNumber = $User.EmployeeNumber
    $HomeDirectory = $empshare + $user.sAMAccountName
    Get-ADUser -Filter {EmployeeNumber -eq $EmployeeNumber} | Set-ADUser -Email $User.mail -sAMAccountName $User.sAMAccountName -userPrincipalName "$($User.sAMAccountName)@sfccmo.edu" -Replace @{ProxyAddresses=$('SMTP:' + $User.mail)} -clear targetAddress -HomeDirectory $HomeDirectory -HomeDrive $homeDrive
    New-Item -Path $HomeDirectory -ItemType directory -force
   
    $IdentityRefenence = $BaseDN + $user.sAMAccountName
    $FileSystemAccessRights = [System.Security.AccessControl.FileSystemRights]”FullControl”
    $InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]::”ContainerInherit","ObjectInherit”
    $PropagationFlags = [System.Security.AccessControl.PropagationFlags]::”None”
    $AccessControl = [System.Security.AccessControl.AccessControlType]::”Allow”
    $AccessRule = NEW-OBJECT System.Security.AccessControl.FileSystemAccessRule ($IdentityReference,$FileSystemAccessRights,$InheritanceFlags,$PropagationFlags,$AccessControl)

    $HomeFolderACL = GET-ACL $HomeDirectory
    $HomeFolderACL.AddAccessRule($Acl)

    SET-ACL –path $HomeDirectory -AclObject $HomeFolderACL

I am getting the two below errors below.  Any ideas?

NEW-OBJECT : Exception calling ".ctor" with "5" argument(s): "Value cannot be null.
Parameter name: identity"
At C:\Accounts\Scriptorium\SFCC-Account-Provisioning-V2d-test.ps1:538 char:19
+     $AccessRule = NEW-OBJECT System.Security.AccessControl.FileSystemAccessRule  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
 
Exception calling "AddAccessRule" with "1" argument(s): "Value cannot be null.
Parameter name: rule"
At C:\Accounts\Scriptorium\SFCC-Account-Provisioning-V2d-test.ps1:541 char:5
+     $HomeFolderACL.AddAccessRule($Acl)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException


Viewing all articles
Browse latest Browse all 6937

Trending Articles