← script library

File and Folder Management PowerShell Script

Files & FoldersJanuary 10, 2025

In this post, we will explore a useful PowerShell script that demonstrates how to manage files and folders effectively. This script will allow you to create a directory, copy a file, and delete a specified file. This is a great way for both beginners and advanced users to familiarize themselves with file and folder operations using PowerShell.

powershell
# Define the path for the new directory
$directoryPath = 'C:\TestDirectory'
# Create the new directory
New-Item -Path $directoryPath -ItemType Directory -Force

# Define the source file and destination path
$sourceFile = 'C:\SourceFile.txt'
$destinationPath = 'C:\TestDirectory\SourceFile.txt'
# Copy the file to the new directory
Copy-Item -Path $sourceFile -Destination $destinationPath -Force

# Remove the original file
Remove-Item -Path $sourceFile -Force

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.