This PowerShell script will help you manage files in a directory by organizing them into subfolders based on their file extensions. Follow the steps below to implement it effectively.
powershell
$targetDirectory = "C:\Your\Target\Directory"
$files = Get-ChildItem -Path $targetDirectory -File
foreach ($file in $files) {
$extension = $file.Extension.TrimStart('.')
$subfolderPath = Join-Path -Path $targetDirectory -ChildPath $extension
if (-not (Test-Path -Path $subfolderPath)) {
New-Item -ItemType Directory -Path $subfolderPath | Out-Null
}
$destinationPath = Join-Path -Path $subfolderPath -ChildPath $file.Name
Move-Item -Path $file.FullName -Destination $destinationPath
}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.