$cs.Ini_ReadEntry
Description
Section titled “Description”Reads a value from a classic INI file. Returns an empty string if the section/variable combination isn’t found in the file. The maximum value length that can be read is 255 characters.
Syntax
Section titled “Syntax”$cs.Ini_ReadEntry(string filepath, string section, string variable)
Parameters
Section titled “Parameters”filepath (String)
Section titled “filepath (String)”Path to the INI file. Throws a FileNotFoundException if this file doesn’t exist.
section (String)
Section titled “section (String)”Section in the INI file to read from.
variable (String)
Section titled “variable (String)”Variable name under the section to read.
Return value
Section titled “Return value”String, the value read, or an empty string if not found.
Example
Section titled “Example”Read a migration flag to decide whether old settings still need to be migrated:
$iniFile = "$env:ProgramData\Contoso\App\app.ini"$version = $cs.Ini_ReadEntry($iniFile, "migration", "firstRunVersionFlag")$cs.Job_WriteLog("firstRunVersionFlag is currently: $version")Read a value and fall back to a sensible default when it comes back empty (not found):
$iniFile = Join-Path $env:ProgramData "Contoso\App\settings.ini"$logLevel = $cs.Ini_ReadEntry($iniFile, "logging", "level")if ([string]::IsNullOrEmpty($logLevel)) { $logLevel = "Info" $cs.Job_WriteLog("logLevel not set in config, defaulting to '$logLevel'")}