Set-FilesFileContent

Writes a whole remote file from text or bytes.

Syntax

__AllParameterSets

Set-FilesFileContent [-Path] <string> [-Value] <Object> [-MkdirParents]
 [-Connection <FilesConnection>] [-WorkspaceScope <long>] [-NoWorkspaceScope] [-WhatIf] [-Confirm]

Description

Set-FilesFileContent writes one file at -Path from everything given to -Value, whether piped or passed, and uploads it once, with the engine's upload, after the last value has arrived. Strings are joined into one UTF-8 text without a byte order mark, each string after the first on a new line (the platform's newline, CRLF on Windows), and no newline is added after the last; bytes and byte arrays are written one after another, as they were when given, even if the command that gave an array changes or reuses it afterwards. A single string or byte array is therefore written exactly as given. The file is created, or replaced once the upload completes; until then any file already there is unchanged. Use Send-FilesFile for a large file, a local file or a stream.

Text and bytes together, $null and values of any other type are refused with Files.InvalidArgument before anything is sent. A pipeline ended early by a terminating error or by being stopped, such as with Ctrl+C, sends nothing either. A non-terminating error earlier in the pipeline does not end it, and the values that still arrive are written: when the file must not be written after such an error, make it terminating, for example with -ErrorAction Stop on the command that produces the content. When the pipeline gives no value at all, nothing is written; to write an empty file, give -Value ''.

-WhatIf describes the one upload, with the size of all the content, without contacting Files.com, and -Confirm asks once.

Examples

Example 1: Write a text file

@{ enabled = $true } | ConvertTo-Json | Set-FilesFileContent -Path config/settings.json

Replaces config/settings.json with the JSON text.

Example 2: Write bytes into a new folder

Set-FilesFileContent -Path exports/2026/data.bin -Value ([System.IO.File]::ReadAllBytes("$PWD/data.bin")) -MkdirParents

Creates exports/2026 if missing.

Example 3: Write lines as one file

Get-Content ./hosts.txt | Where-Object { $_ -notmatch '^#' } | Set-FilesFileContent -Path config/hosts.txt

Uploads the lines that are not comments as one file, with one upload. To upload a local text file exactly, with its own line endings, give it as one string with Get-Content -Raw, or use Send-FilesFile.

Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

  • Type: System.Management.Automation.SwitchParameter
  • Parameter sets: (All)
  • Aliases: cf

-Connection

The connection to use, from Connect-FilesAccount. Defaults to the current runspace's default connection.

  • Type: FilesCom.PowerShell.FilesConnection
  • Parameter sets: (All)

-MkdirParents

Creates missing folders above the file.

  • Type: System.Management.Automation.SwitchParameter
  • Parameter sets: (All)

-NoWorkspaceScope

Runs this command's requests in no workspace, even if the connection has one. The connection itself is unchanged.

  • Type: System.Management.Automation.SwitchParameter
  • Parameter sets: (All)

-Path

The remote file, used exactly as written.

  • Type: System.String
  • Parameter sets: (All) (required, position 0)

-Value

The content: strings, written as UTF-8 with each string after the first on a new line, or bytes and byte arrays, written as they were when given. Every value piped goes into the one file.

  • Type: System.Object
  • Parameter sets: (All) (required, position 1, pipeline input)

-WhatIf

Runs the command in a mode that only reports what would happen without performing the actions.

  • Type: System.Management.Automation.SwitchParameter
  • Parameter sets: (All)
  • Aliases: wi

-WorkspaceScope

Runs this command's requests in this workspace instead of the connection's, including workspace 0. The connection itself is unchanged.

  • Type: System.Int64
  • Parameter sets: (All)

Common Parameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

  • System.Object: Strings, or bytes and byte arrays, as -Value; everything piped is written as one file.

Outputs

  • None: Nothing.

Notes

The content is held in memory; nothing is uploaded until it has all been given, and the connection's -OperationTimeout counts the time the pipeline takes to give it. Piping a byte array sends it one byte at a time; for large content, give the array to -Value, or use Send-FilesFile. See about_FilesCom for connections, errors and previewing changes.

  • Get-Help about_FilesCom