Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PsIni doesn't work with C:\ProgramData\Microsoft\Network\Connections\Pbk\rasphone.pbk #57

Open
Mike-FUT opened this issue Aug 21, 2020 · 5 comments

Comments

@Mike-FUT
Copy link

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.

@lipkau
Copy link
Owner

lipkau commented Aug 21, 2020

please provide the content of the original file

@Mike-FUT
Copy link
Author

Mike-FUT commented Aug 23, 2020

rasphone.txt

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

@devio
Copy link

devio commented Nov 5, 2020

@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

devio pushed a commit to devio/PsIni that referenced this issue Nov 5, 2020
- Bugfix: Fixes lipkau#57
- If a key already exist in table, its values are stored as
  System.Collections.ArrayList. However, System.Collections.ArrayList
  overwrites the first value before it has been added to the list
  itself.
@PsychoData
Copy link

Just saw that #58 was in here and trying to tackle the Duplicate Key issue.
I just submitted #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

image

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

@PsychoData
Copy link

However, like I mentioned here #60 (comment)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants