0
0
PowerShellscripting~30 mins

Copy-Item and Move-Item in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Copy-Item and Move-Item
📖 Scenario: You are organizing files on your computer. You want to copy some files to a backup folder and move others to a different folder for processing.
🎯 Goal: Learn how to use Copy-Item to copy files and Move-Item to move files in PowerShell.
📋 What You'll Learn
Create a list of file names
Create variables for source and destination folders
Use Copy-Item to copy files
Use Move-Item to move files
Print the final list of files in the destination folders
💡 Why This Matters
🌍 Real World
Organizing and managing files is a common task for system administrators and anyone working with many files. Automating copy and move operations saves time and reduces errors.
💼 Career
Knowing how to use PowerShell commands like Copy-Item and Move-Item is essential for IT professionals managing Windows systems and automating file management tasks.
Progress0 / 4 steps
1
Create a list of file names
Create a variable called files and assign it an array with these exact file names: 'report1.txt', 'report2.txt', 'summary.docx'.
PowerShell
Need a hint?

Use @( ) to create an array in PowerShell.

2
Create source and destination folder variables
Create two variables: $sourceFolder with value 'C:\Data\Source' and $backupFolder with value 'C:\Data\Backup'.
PowerShell
Need a hint?

Use single quotes for the folder paths and double backslashes \\ to escape backslashes.

3
Copy files to backup folder
Use a foreach loop with variable $file to iterate over $files. Inside the loop, use Copy-Item to copy each file from $sourceFolder to $backupFolder. Use Join-Path to build full file paths.
PowerShell
Need a hint?

Use Join-Path to combine folder and file names safely.

4
Move files to processing folder and print results
Create a variable $processingFolder with value 'C:\Data\Processing'. Use a foreach loop with variable $file to move each file from $sourceFolder to $processingFolder using Move-Item. Then print the message "Moved: <file>" for each file moved.
PowerShell
Need a hint?

Use Write-Output to print messages in PowerShell.