Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to use a configuration file with a PowerShell script ?

for example, the configuration file:


and then call this information in the PS1 script:

start-process iexplore.exe $Link1

thanks in advance for your help!!

share|improve this question

Thanks a lot for your help Dennis and Tim!!

Your answers put me on the good track and I found this






Get-Content "C:\settings.txt" | foreach-object -begin {$h=@{}} -process { $k = [regex]::split($_,'='); if(($k[0].CompareTo("") -ne 0) -and ($k[0].StartsWith("[") -ne $True)) { $h.Add($k[0], $k[1]) } }


After executing the code snippet, a variable ($h) will contain the values in a HashTable.

Name                           Value
----                           -----
MySetting1                     value
VerboseLogging                 True
WaitForTime                    20
OutputFile                     "C:\output.log"
InputFile                      "C:\Users.txt"

*To get an item from the table use the command $h.Get_Item("MySetting1").*

share|improve this answer
You can also get the settings out by the much friendlier $h.MySetting1 – Ryan Shillington Nov 13 '15 at 19:54

There's a good thread here which shows this code (quoting from the linked thread):

# from
param ($file)

$ini = @{}
switch -regex -file $file
    "^\[(.+)\]$" {
        $section = $matches[1]
        $ini[$section] = @{}
    "(.+)=(.+)" {
        $name,$value = $matches[1..2]
        $ini[$section][$name] = $value

Then you can do:

PS> $links = import-ini links.ini
PS> $links["search-engines"]["link1"]
PS> $links["vendors"]["link1"]

Assuming an INI file that looks like this:


Unfortunately the regexes are missing from the code at the link so you'll have to reproduce them, but there's a version that handles files without section headers and lines that are comments.

share|improve this answer
You can handle comments easily by just adding another case to the switch with '^#' {}. Also you can access hashtable contents with a dot as well, so $links.vendors.link1 should work too which might be a little better to read. – Joey Oct 20 '10 at 7:20

yes, the cmdlets you're looking for are get-content and select-string.

$content=get-content C:\links.txt
start-process iexplore.exe $content[0]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.