---
title: "Ensure-File"
---
Ensures the existence of a file on a server.
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.
Name | Format | Script Usage | Usage 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 | Default value is "True". |
Last write time | DateTime | Modified | The last write time (UTC) of the file or directory. |
# 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
);