Skip to content

Instantly share code, notes, and snippets.

@xsolon
Created November 4, 2017 14:34
Show Gist options
  • Save xsolon/5391db8202bf91c2920705cb93c5606c to your computer and use it in GitHub Desktop.
Save xsolon/5391db8202bf91c2920705cb93c5606c to your computer and use it in GitHub Desktop.
Pfx access for application pool
$friendlyName = 'cert friendly name'
$location = 'Cert:\LocalMachine\my';
#get cert by friendly name
$cert = Get-ChildItem -Path $location | Where { $_.FriendlyName -eq $friendlyName};
#location of pfx on file system
$keyName = $cert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
$keyPath = [System.IO.Path]::Combine("$env:ProgramData\Microsoft\Crypto\RSA\MachineKeys\",$keyName)
$userName = "IIS AppPool\services"
#icacls $keyPath /grant "$userName`:(F)"
$acl = Get-Acl $keyPath
$ar = New-Object system.security.accesscontrol.filesystemaccessrule($userName,"FullControl","None", "None", "Allow")
$acl.SetAccessRule($ar)
Set-Acl $keyPath $acl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment