Skip to content

$cs.File_AppendToFile

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.

$cs.File_AppendToFile(string file, string text)

Full path to the file to append the line to. The file must already exist.

Text to add as a new line at the end of the file.

None.

Terminal window
$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:

Terminal window
$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:

Terminal window
$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")

$cs.File_DeleteLineInFile