Powershell – Edit local policy via powershell

group-policypowershellwindows 7

i'm searching for a way to edit this policy via powershell :

Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Delegating Fresh Credentials with NTLM-only Server Authentication

I want to activate it, and put * in value.

I already tried it, but it doesn't work :

$allowed = @('WSMAN/*')            

$key = 'hklm:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation'
if (!(Test-Path $key)) {
    md $key
}
New-ItemProperty -Path $key -Name AllowFreshCredentials -Value 1 -PropertyType Dword -Force            

$key = Join-Path $key 'AllowFreshCredentials'
if (!(Test-Path $key)) {
    md $key
}
$i = 1
$allowed |% {
    New-ItemProperty -Path $key -Name $i -Value $_ -PropertyType String -Force
    $i++
}

It doesn't work, Powershell generates me an error "The WinRM client cannot process the request. A computer policy does not allow the delegation of the user credentials to the target computer"

I also tried to activate manually the policy and it works.

My computer is not in domain, but in workgroup and i'm running Windows 7 with Powershell v4.0.

Thanks for your help

Best Answer

This is how i resolved it :

New-ItemProperty -Path 'hklm:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation' -Name "AllowFreshCredentialsWhenNTLMOnly" -Value 1 -PropertyType Dword -Force     

New-Item -Path 'hklm:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation'  -Name "AllowFreshCredentialsWhenNTLMOnly" -Value "Default Value" -Force

New-ItemProperty  -Path 'hklm:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation\AllowFreshCredentialsWhenNTLMOnly' -Name "1" -PropertyType "String" -Value '*'