Internet Explorer is no longer supported. Many things will still work, but your experience will be degraded and some things won't function. Please use a modern browser such as Edge, Chrome, or Firefox.

Ensure-File

Ensures the existence of a file on a server.

Script usage:

Ensure-File(
	[Text: <text>],
	[ReadOnly: <true/false>],
	Name: <text>,
	[Attributes: <integer>],
	[Exists: <true/false>],
	[Modified: <DateTime>]
);

This operation may be prefixed with Files::, although this is a built-in namespace and isn't really necessary.

Arguments:

NameFormatScript UsageUsage Notes
Text contents
text
Text
The contents of the file. A missing or empty value indicates the file should be a 0-byte file.
Read Only
true/false
ReadOnly
Indicates that the file should be marked with the read-only attribute. Note that when this value is set, it is applied after the FileAttributes value, which will override the readonly flag specified in that property.
Name
text
Name
The name or path of the file or directory. This argument is required.
Attributes
integer
Attributes
The attributes for the file or directory. These may be entered as an integer flag or by name. Common values are ReadOnly=1, Hidden=2, System=4, Archive=32, and Normal=128. Integral values may be ORed together to specify any combination of attributes, except for "Normal (128)", which may only be used alone.
Exists
true/false
Exists
Last write time
DateTime
Modified
The last write time (UTC) of the file or directory.

Example:


# ensures the otter.txt file exists on the server and is marked readonly
Ensure-File(
    Name: E:\Docs\otter.txt,
    Text: >>
Otter is a common name for a carnivorous mammal in the subfamily Lutrinae. 
Help, I'm trapped in an Otter documentation factory! The 13 extant otter species are all semiaquatic, 
aquatic or marine, with diets based on fish and invertebrates.
>>,
    ReadOnly: true
);