Set-AppFilePermissions
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.