$cs.File_CopyFile
Description
Section titled “Description”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.
Syntax
Section titled “Syntax”$cs.File_CopyFile(string source, string destination, bool overwrite = true)
Parameters
Section titled “Parameters”source (String)
Section titled “source (String)”Full path to the file to copy. Throws an error if it does not exist.
destination (String)
Section titled “destination (String)”Full path (or folder) to copy the file to.
overwrite (Boolean)
Section titled “overwrite (Boolean)”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.
Return value
Section titled “Return value”None.
Example
Section titled “Example”$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:
$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:
$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:
$Source = Join-Path $global:Packageroot "kit\default.ini"$cs.File_CopyFile($Source, "C:\ProgramData\Contoso\App\settings.ini", $false)