How to Read the values from Config File – PowerShell

Sathish Nadarajan
 
Solution Architect
May 14, 2016
 
Rate this article
 
Views
15321

Almost in all the PowerShell Scripts, either we will be reading the configuration values from CSV File or an XML file. Let us Keep the code clean to read the value from the XML File.

 function LoadConfigXML()
 {
     $Progress = "0:Entered"
     Write-Host "Entered into LoadConfigXML Method" -ForegroundColor Yellow 
     Add-Content "$ProgressFile" "Entered into LoadConfigXML Method"
     
     $ConfigXmlPath = $scriptBase + "Configuration.xml"
     
     [Xml]$Config = Get-Content $ConfigXmlPath  
     
     Write-Host "Finished LoadConfigXML Method" -ForegroundColor Green 
     Add-Content "$ProgressFile" "Finished LoadConfigXML Method"
     
     return $Config
     
     $Progress = "0:Success"
 }
 
 
 

From the main thread, we can call the below line.

# Load the Configuration File

$Config = LoadConfigXML

In the next article, let us see, how to segregate the PS1 files into small files and load them on the main file.

Happy Coding,

Sathish Nadarajan.

Category : PowerShell

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment