Created
November 4, 2017 14:34
-
-
Save xsolon/5391db8202bf91c2920705cb93c5606c to your computer and use it in GitHub Desktop.
Pfx access for application pool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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