Set-AppFilePermissions

  • 5 July 2019
  • Sean Huggans
Description: 

Sets the passed permissions on the given file

Language: 
Powershell
Usage Type: 
Packaging Function
Script Source: 
function Set-AppFilePermissions ($Setting, $FilePath) {
########################################
# Modify Dirrctory Permissions
# Function Date: 19.7.5.1
# Function By: Sean Huggans
########################################
# Usage Note 1: function is dependent on the standard logging function being present
# Example 1 - "Set-AppDirPermissions -Setting "Modify" -DirPath "C:\Program Files\Application X"
    if (!(test-path -Path $FilePath)) {
        new-item -ItemType directory -Path $FilePath -force -erroraction SilentlyContinue
    }
    if (($Setting) -and ($FilePath)) {
        try {
            Log-Action -Message "Setting ""$($Setting)"" permission on ""$($FilePath)""..."
            $InstallfileObject = Get-Item -LiteralPath $FilePath -ErrorAction Stop
            $ACL = $InstallfileObject.GetAccessControl()
            $Rule = New-Object System.Security.AccessControl.FileSystemAccessRule("everyone","$($Setting)","Allow")
            $ACL.SetAccessRule($Rule)
            $InstallfileObject.SetAccessControl($ACL)
            Log-Action -Message " - Success!"
            return $true
        } catch {
            Log-Action -Message " - Error!"
            return $false
        }
    } else {
        Log-Action -Message " - Error! (Incomplete Parameters Passed)"
        return $false
    }
}
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.