0

I'm a newbie in Powershell. This is probably quite simple, but for a newbie is not that obvious. I have a file with credentials: credentials.cfg with format like this

[server_1]
username=user_1
password=pass_1

[server_2]
username=user_2
password=pass_2

I need to read this file and based on a parameter to get the username and password to create a connection string, so to say, to populate $username and $password in my PS script.

The format is always the same:

[block]
username=x
password=y

Thanks in advance

jnuno37
  • 1
  • 1
  • 2
    Does this answer your question? [INI file parsing in PowerShell](https://stackoverflow.com/questions/417798/ini-file-parsing-in-powershell). While your file has a `.cfg` extension, the syntax looks like a classic INI file. And parsing it is not *that* obvious, as there is no built-in cmdlet to do it directly. – Jeroen Mostert May 25 '22 at 09:23
  • Will the file always have content in this pattern? Also, please edit your question to give an example of what output you expect. – shree.pat18 May 25 '22 at 09:23
  • I've updated the question and I'm looking at that INI parsing solution. Probably it will be useful, even if not that clear for a newbie – jnuno37 May 25 '22 at 09:52

0 Answers0