$cs.File_AppendToFile
Description
Section titled “Description”Appends text as a new line to the end of file. The file must already exist — this function does not create it, and throws an error if it is missing.
Syntax
Section titled “Syntax”$cs.File_AppendToFile(string file, string text)
Parameters
Section titled “Parameters”file (String)
Section titled “file (String)”Full path to the file to append the line to. The file must already exist.
text (String)
Section titled “text (String)”Text to add as a new line at the end of the file.
Return value
Section titled “Return value”None.
Example
Section titled “Example”$cs.File_AppendToFile("$env:windir\System32\Drivers\etc\hosts","127.0.0.1 assets.cloud.barco.com")Since the file must already exist, check for it first (and create it if needed) before appending a line to an application’s config file:
$ConfigFile = "$env:ProgramData\Contoso\App\app.conf"if (-not $cs.File_ExistFile($ConfigFile)) { $cs.File_CreateDirectory((Split-Path $ConfigFile)) New-Item -Path $ConfigFile -ItemType File | Out-Null $cs.Job_WriteLog("Created new config file: $ConfigFile")}$cs.File_AppendToFile($ConfigFile, "UpdateChannel=Stable")Append a marker line to the PowerPack’s own log after a successful install, so it’s easy to confirm which package version wrote to the machine:
$MarkerFile = Join-Path $global:AppLogFolder "install-history.log"if (-not $cs.File_ExistFile($MarkerFile)) { New-Item -Path $MarkerFile -ItemType File | Out-Null $cs.Job_WriteLog("Created install history file: $MarkerFile")}$cs.File_AppendToFile($MarkerFile, "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Installed version 3.4.1")