How to Read the values from Config File - PowerShell

Sathish Nadarajan
SharePoint MVP
Published On :   14 May 2016
Visit Count
Today :  5    Total :   6495
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial

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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.

Protect Your SharePoint