-
Notifications
You must be signed in to change notification settings - Fork 52
Get IniContent
This parameters describes the path of the file to be read. Ideally this would be a path to a file with the INI extension. Type: String
This parameter must be provided. The value cannot be empty or null and must be pointing to an existing file.
The path is tested with Test-Path $_
This parameter can be provided over the pipeline:
$ArrayOfIniContent = Get-ChildItem c:\sample\*.ini | Get-IniContent
Name Value ---- ----- Key1 Foo Key2 Bar Comment1 ;comment line
This parameters specifies what characters characterize a comment line. Type: Array of chars
By default a semicolon is used ;
. This can be extended or overwritten.
Reading a INI file which used #
as comment character:
Get-IniContent -FilePath "C:\sample\config.ini" -CommentChar @("#")
Name Value ---- ----- key1 Foo Key2 Bar Comment1 #comment line
This parameter keeps the function from returning comment lines. Type: Switch
Get-IniContent -FilePath "C:\sample\config.ini" -IgnoreComments
Name Value ---- ----- Key1 Foo Key2 Bar
By default the Module provides an alias Get-INI
for the function.
This section uses these two INI files:
--FILE 1: ftp_profile.ini--
[settings]
;server address
server = ftp://contoso.com
;Username
user = admin
;Password
password = Password!
;FTP Mode
mode = passive
--FILE 2: transfer.ini--
[upload] files = index.html,styles.css,script.js
overwrite = true
source = c:\temp\website\[download]
files = images/loading.gif,images/logo.png
destination = c:\temp\website
Get all data
Get-ChildItem *.ini | Get-IniContent
Name Value ---- ----- settings {Comment1, server, Comment2, user...} upload {files, overwrite, source} download {files, destination}
Get data to connect to FTP from Example 1
$ftpData = Get-ChildItem *.ini | Get-IniContent
($ftpData | ? {$_["settings"]})["settings"]
Name Value ---- ----- Comment1 ;server address server ftp://contoso.com Comment2 ;Username user admin Comment3 ;Password password Password! Comment4 ;FTP Mode mode passive
Get data to connect to FTP
$ftpData = Get-IniContent -FilePath "ftp_profile.ini"
$ftpData["settings"]
Name Value ---- ----- Comment1 ;server address server ftp://contoso.com Comment2 ;Username user admin Comment3 ;Password password Password! Comment4 ;FTP Mode mode passive
Get data to connect to FTP ignoring comments
$ftpData = Get-IniContent -FilePath "ftp_profile.ini" -IgnoreComments
$ftpData["settings"]
Name Value ---- ----- server ftp://contoso.com user admin password Password! mode passive
Loop through all file to be uploaded
$ftpTransfer = Get-IniContent -FilePath transfer.ini
$ftpTransfer["upload"]["files"].Split(",") | % {Write-Host "Upload: $_"}
Upload: index.html Upload: styles.css Upload: script.js