Custom script samples
These samples show practical ways to use custom scripts in Automate MFT tasks.
Sample scripts
Add a new file to the cache
{#codeblock_n1y_xwj_c3c}
$newItem = Add-MftItem -Name 'mine.txt'
Set-MftContent -Item $newItem -Value 'this is the new item content'
Remove files that are named ‘1.txt’ and change the content of the others
{#codeblock_ehj_1xj_c3c}
$items = Get-MftItem
foreach ($item in $items) {
if ($item.Name -eq ""1.txt"") {
Remove-MftItem -Item $item
}else {
Set-MftContent -Item $item -Value 'brand new content'
}
}
Rename files and change the output directory to new-output
{#codeblock_bnh_cxj_c3c}
$items = Get-MftItem
foreach ($item in $items) {
Rename-MftItem -Item $item -NewName "new-output/$($item.Name)-renamed"
}