Functions/Validations/Test-UserWriteAccessToFolder.ps1

<#
    .SYNOPSIS
    Checks if user has write permission to folder
    Related to: General
 
    .DESCRIPTION
    Executed tasks:
        - Retreive the folder permission
        - Filter the user name in the permission groups
        - returns true if user has access to folder
        - returns false if user has not access to folder
     
    Preconditions:
        - Folder path has to be retreived
        - User name has to be retreived
 
#>

function Test-UserWriteAccessToFolder() {
    [CmdletBinding()]
    [Alias('UserHasWriteAccessToFolder')]
    Param
    (
        [parameter(Mandatory = $true)]
        [string] $UserName,
        [parameter(Mandatory = $true)]
        [string] $FolderPath
    )
    PROCESS {
        $permission = (Get-Acl $FolderPath).Access | Where-Object { $_.IdentityReference -match $UserName } | Select-Object IdentityReference, FileSystemRights

        If ($permission) {
            $permission | ForEach-Object { Write-Verbose "User $($_.IdentityReference) has '$($_.FileSystemRights)' rights on folder $FolderPath" }
            return new-object psobject -Property @{User = $permission.IdentityReference; Permissions = @( $permission.FileSystemRights ) }
        }
        Else {
            Write-Verbose "$User doesn't have any permission on $FolderPath"
            return $false;
        }
    }
}
Export-ModuleMember -Function Test-UserWriteAccessToFolder -Alias UserHasWriteAccessToFolder