PsIni doesn't work with C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk
Not sure if you consider amending the scripts because the rasphone.pbk is a rather special INI file. The issues are:
- There are two Device entries per section, one is "Device" and one is "DEVICE" so it PsIni would need to be case sensitive optionally
- There are multiple lines of "CustomAuthData" per section
- When writing the file and selecting "Out-IniFile -FilePath $iniPath -Encoding UTF8" it will write the encoding in UTF-8-BOM instead of UTF-8 (not sure though if that is causing issues but I wanted to mention it)
When writing the file with Out-IniFile the mentioned wrong elements look like this - the (...) is added by me:
CustomAuthData=System.Collections.ArrayList D88F7E15760070006E002D0066007500740(...) instead of CustomAuthData=D88F7E15760070006E002D006(...)
or
DEVICE=System.Collections.ArrayList vpn DEVICE=vpn instead of Device=WAN Miniport (SSTP) DEVICE=vpn
Since this is a rather special INI file I'm not sure if it is worth looking into but I would be very happy to see it working since modifying the rasphone.pbk file is the only option to change certain settings for VPN connections in Windows.
please provide the content of the original file
File is attached (renamed to .txt and internal data replaced with dummys).
These are the commands I'm using which basically "destroy" the file:
$iniPath = "C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk"
$ini = Get-IniContent $iniPath
$ini["Test-VPN"]["ExcludedProtocols"]="8"
$ini["Test-VPN"]["PreferredHwFlow"]="1"
$ini["Test-VPN"]["PreferredProtocol"]="1"
$ini["Test-VPN"]["PreferredCompression"]="1"
$ini["Test-VPN"]["PreferredSpeaker"]="1"
$ini["Test-VPN"]["IpDnsAddress"]="10.117.1.11"
$ini["Test-VPN"]["IpDns2Address"]="10.117.1.12"
$ini["Test-VPN"]["IpNameAssign"]="2"
$ini["Test-VPN"]["IpNBTFlags"]="0"
$ini["Test-VPN"]["DisableClassBasedDefaultRoute"]="1"
$ini["Test-VPN"]["AutoTiggerCapable"]="1"
$ini | Out-IniFile -FilePath $iniPath -Encoding UTF8 -Force
@lipkau The first appearance of the value is overwritten with the arraylist in Get-IniContent. You should rather safe the previous value before creating an arraylist. Fix:
if ($ini[$section][$name] -is [string]) {
$first = $ini[$section][$name]
$ini[$section][$name] = [System.Collections.ArrayList]::new()
$ini[$section][$name].Add($first) | Out-Null
$ini[$section][$name].Add($value) | Out-Null
}
cheers,
Thorsten
Just saw that https://github.com/lipkau/PsIni/pull/58 was in here and trying to tackle the Duplicate Key issue. I just submitted https://github.com/lipkau/PsIni/pull/63 before I saw that. Either way, though - in my testing it seemed like I was getting a second key of my "duplicate" and then continuing forward from there with the Arraylist

and when written out, it resulted in this annoying double-expansion of the ArrayList

However, like I mentioned here https://github.com/lipkau/PsIni/issues/60#issuecomment-916692207 I think either of mine or @devio 's solutions would also possibly raise an issue of moving entries up/down within a file
so
key = value # 'comment line' # 'comment line' key = value # 'comment line'would end up like this I believe
# 'comment line' # 'comment line' key = value key = value # 'comment line'
or possibly like this for devio's solution - I think - I didn't check his personally
key = value
key = value
# 'comment line'
# 'comment line'
# 'comment line'
To fully allow for duplicate keys, potentially spread through the entire file & assuming their positioning relative to other entries within a section (or lack of a section) is important - I'm not sure how to get around the bunching problem