Take-SystemOwnerShipAndAllowModify
Description:
Take ownership as system and grant system modify of a file
Language:
PowerShell
Usage Type:
Packaging Function
Script Source:
Function Take-SystemOwnerShipAndAllowModify ($FilePath) { ######################################## # Take ownership as system and grant system modify of a file # Function Date: 23.5.7.1 # Function By: Sean Huggans ######################################## Try { $AccountObject = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList 'SYSTEM' $SSFile = Get-Item -path $FilePath $ACL = Get-Acl -Path $SSFile.FullName $ACL.SetOwner($AccountObject) $SystemAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("SYSTEM","Modify","Allow") $ACL.AddAccessRule($SystemAccessRule) Set-Acl -Path $SSFile.FullName -AclObject $ACL -ErrorAction Stop Log-Action -Message "Successfully took ownership and allowed modify on the provided file ""$($FilePath)""." return $true } catch { Log-Action -Message "Failed to take ownership and allow modify on the provided file ""$($FilePath)"" ($($PSItem.ToString()))!" 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.