I am writing a PowerShell script that needs to edit the xml config file for the Claims to Windows Token Service (C2WTS) as "any user" but have been unable to save the file once I have made changes to the XML object. Using the following code:
$xml.load("C:\Program Files\Windows Identity Foundation\v3.5\c2wtshost.exe.config")
changes here
$xml.save("C:\Program Files\Windows Identity Foundation\v3.5\c2wtshost.exe.config")
Running this code, I get the error:
Exception calling "Save" with "1" argument(s): "Access to the path 'C:\Program Files\Windows Identity Foundation\v3.5\c2wtshost.exe.config' is denied."
I have tried setting the ACL so that the user running the script can then edit the XML file with the following code:
$acl = Get-Acl "C:\Program Files\Windows Identity Foundation\v3.5\c2wtshost.exe.config"
$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule($user,"FullControl","Allow")
$acl.SetAccessRule($Ar)
Set-Acl "C:\Program Files\Windows Identity Foundation\v3.5\c2wtshost.exe.config" $acl
but get an error returned as:
"Set-Acl : Attempted to perform an unauthorized operation."
Can anyone help me get to a point where I can save the changes I have made to the XML file?