Private/FixVagrantPrivateKeyPerms.ps1
function FixVagrantPrivateKeyPerms { [CmdletBinding()] Param ( [Parameter(Mandatory=$True)] [string]$PathToPrivateKey ) ##### BEGIN Variable/Parameter Transforms and PreRun Prep ##### $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name if (! $(Test-Path $PathToPrivateKey)) { Write-Error "The path $PathToPrivateKey was not found! Halting!" $global:FunctionResult = "1" return } ##### END Variable/Parameter Transforms and PreRun Prep ##### ##### BEGIN Main Body ##### $SecurityDescriptor = Get-NTFSSecurityDescriptor -Path $PathToPrivateKey $SecurityDescriptor | Disable-NTFSAccessInheritance -RemoveInheritedAccessRules $SecurityDescriptor | Clear-NTFSAccess $SecurityDescriptor | Add-NTFSAccess -Account SYSTEM -AccessRights FullControl -AppliesTo ThisFolderOnly $SecurityDescriptor | Add-NTFSAccess -Account $CurrentUser -AccessRights FullControl -AppliesTo ThisFolderOnly $SecurityDescriptor | Set-NTFSSecurityDescriptor ##### END Main Body ##### } |