Skip to content

$cs.File_CopyFile

Copies source to destination. If destination is an existing folder, or ends with a path separator (\), the source’s filename is automatically appended to it, so you can pass just a target folder. The destination’s parent folder is created automatically if it doesn’t exist.

$cs.File_CopyFile(string source, string destination, bool overwrite = true)

Full path to the file to copy. Throws an error if it does not exist.

Full path (or folder) to copy the file to.

Overwrite the destination if it already exists. Default is $true. If set to $false and the destination file already exists, the copy is silently skipped — no error is raised.

None.

Terminal window
$cs.File_CopyFile("C:\Program Files\CapaInstaller\dummy.exe","C:\Windows\dummy2.exe")

This copies a log file to the PowerPack’s log folder, making it visible in the CapaInstaller Console:

Terminal window
$Destination = Join-Path $global:AppLogFolder "dism.log"
$cs.File_CopyFile("C:\Windows\Logs\DISM\dism.log", $Destination)

Passing a folder (or a path ending in \) as the destination copies the file into it under its original filename:

Terminal window
$Source = Join-Path $global:Packageroot "kit\license.lic"
$cs.File_CopyFile($Source, "C:\Program Files\Contoso\App\")

When deploying a default configuration file, use overwrite=$false so an end user’s existing customized copy is left untouched:

Terminal window
$Source = Join-Path $global:Packageroot "kit\default.ini"
$cs.File_CopyFile($Source, "C:\ProgramData\Contoso\App\settings.ini", $false)

$cs.File_CopyTree $cs.File_ExistFile