EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PowerShell Move-Item

By Chirag NagarekarChirag Nagarekar

Home » Data Science » Data Science Tutorials » PowerShell Tutorial » PowerShell Move-Item

PowerShell Move-Item

Introduction to Move-Item in PowerShell

In this article, we will learn about PowerShell Move-Item. Move-Item cmdlet in Powershell works similar to the cut / Paste option in Windows. It moves files, folders, registry and along with their properties, contents and child items from one location to another location. The location must be supported by the same provider. When you move items from one location to another then it basically deletes items from the original location and moves to another location.

Syntax 

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Move-Item
[-Path] <String[]>
[[-Destination] <String>] [-Force] [-Filter <String>] [-Include <String[]>] [-Exclude <String[]>] [-PassThru] [-Credential <PSCredential>] [-WhatIf] [-Confirm] [<CommonParameters>]

Syntax 

Move-Item
-LiteralPath <String[]>
[[-Destination] <String>] [-Force] [-Filter <String>] [-Include <String[]>] [-Exclude <String[]>] [-PassThru] [-Credential <PSCredential>] [-WhatIf] [-Confirm] [<CommonParameters>]

Parameters of PowerShell Move-Item

Below are the parameter used in PowerShell Move-Item:

  • Path: Specifies the source location of the file. The default directory is the current directory. You can also specify (.) as the current location. Wildcard parameters are permitted. You can use wildcard (*) to refer all items in the directory.
  • LiternalPath: Almost the same as the -path parameter except you need to type exact path value as no wildcard parameters are permitted. No characters are interpreted as a wildcard. If you want to use escape characters then use them under a single quote. Once they are in a single quotation, PowerShell treats escape character as a string. To learn more about escape (special) characters. https://docs.microsoft.com/
  • Destination: Path of the items which are going to move to the desired location. If the destination path is not available then it will throw an exception but you can rename the file name you need to provide a new file name in the destination parameter itself. The default destination is current location and wildcard characters are permitted but the result must specify a single location.
  • Force: Move items to the destination folder without user confirmation. In addition, if any duplicate items are found at destination location then it overwrites them if security permissions are satisfied. It can also move the system’s read-only file.
  • Include: Includes specific file name(s) (C:\temp\test*) or extension(s) (*.pdf) from the source path to move them to destination location. Wildcard characters are permitted. The parameter Include is helpful when the content of the source path specified. For example, at source path c:\temp\* so it will include all files from c:\temp folder and then whatever the filters are set in Include parameter Move-Item cmdlet will work accordingly.
  • Exclude: Excludes specific file name(s) (c:\temp\test*) or extension(s) (*.txt) from the source path so they will not be moved to the destination location. Wild card parameters are permitted. Again you need to use the whole folder or registry content to filter out specific data.
  • Filter: Filter parameter is more efficient than Include and Exclude parameter because it applies filter while retrieving objects rather than filtering objects after value retrieved. The exact syntax of the filter like wildcard support depends on the provider.
  • PassThru: When the PassThru parameter is used, the output of the command returns to the PowerShell console.
  • Credential: If source and destination directories are on different domains or workstations and if they are using different credentials then you need to specify destination host credentials. You can store credentials in a variable using Get-Credential and provide it to the credential parameter. For example, $cred = Get-Credential. If you provide username after –Credential parameter then it will prompt for the password.
  • Whatif: Shows what will happen when the command runs without executing the command.
  • Confirm: Confirms before performing any action. When you use this parameter you get below options. [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is “Y”):
  • CommonParameters: Below is common parameters used with Move-Item cmdlet which are also called advance function parameters. Verbose, -Debug, -ErrorAction, -WarningAction, – InformationAction, -ErrorVariable, -WarningVarible, -InformationVariable, -OutVariable, -OutBuffer, -Pipelinevariable,                   -UseTransacation

Examples to Implement PowerShell Move-Item

Below are the examples of PowerShell Move-Item:

1. Move-Item with Source and Destination

Move-Item -Path D:\Temp\* -Destination D:\Temp1

If you use the wildcard (*) is displayed in the above example, then it will move the folder contents otherwise it will move the entire folder. In the above example, you cannot see which files were moved from source to destination because no explicit parameters specified but when you use PassThru (which returns output in the console itself) or –Verbose parameter then output/process will be displayed in PowerShell console only.

2. Move-Item with – PassThru

Code:

Move-Item -Path D:\Temp\* -Destination D:\Temp1 -PassThru

Output:

PowerShell Move-Item - 1

3. Move-Item with – Verbose

Code:

Move-Item -Path D:\Temp\* -Destination D:\Temp1 -Verbose

Output:

PowerShell Move-Item - 2

4. Move-Item with –  Include

Code:

Move-Item -Path D:\Temp\* -Destination D:\Temp1 –Include *.html -Verbose

Explanation to the above code: In the above example, the script will move all files which have .html extension. When we use only Include parameter script will throw an error for files or folders which don’t have HTML extension.

Output:

PowerShell Move-Item - 3

We can simply eliminate the above exception by –ErrorAction parameter.

Popular Course in this category
Sale
Programming Languages Training (41 Courses, 13+ Projects, 4 Quizzes)41 Online Courses | 13 Hands-on Projects | 322+ Hours | Verifiable Certificate of Completion | Lifetime Access | 4 Quizzes with Solutions
4.5 (8,972 ratings)
Course Price

View Course

Related Courses
Shell Scripting Training (4 Courses, 1 Project)All in One Data Science Bundle (360+ Courses, 50+ projects)Data Visualization Training (15 Courses, 5+ Projects)

Code:

Move-Item -Path D:\Temp\* -Destination D:\Temp1 -Include *.html -ErrorAction Ignore -Verbose

Output:

PowerShell Move-Item - 4

5. Move-Item with – Exclude

Code:

Move-Item -Path D:\Temp\* -Destination D:\Temp1 -Exclude *.html -ErrorAction Ignore -Verbose

Output:

PowerShell Move-Item - 5

In the above example, files will be moved excluding .html files to the destination folder.

6. Move-Item with child items

When we use wildcard character it only includes the items under that folder but not the subfolders. For example, D:\temp\* folder cannot filter files under D:\temp\LGPO or under other subfolders. To do so, we need to first extract the files using the Get-ChildItem and –Recurse parameter and then move them to another location.

Code:

Get-ChildItem -Path D:\Temp -Recurse -Include *.html | Move-Item -Destination D:\Temp1 -Verbose

Output:

child items

7. Move-Item with – Confirm

Code:

Move-Item -Path D:\Temp\* -Destination D:\Temp1 -Confirm -Verbose

It will wait for confirmation from the user before moving any item.

Output:

Confirm

8. Move-Item with -WhatIf

Code:

Move-Item -Path D:\Temp\* -Destination D:\Temp1 -WhatIf

Shows what will happen when the command is executed without actually running it.

Output:

WhatIf

9. Move-Item with – Credential

Code:

Move-Item -Path D:\Temp\* -Destination D:\Temp1 -Credential ad\xyz

The above command will open a credential box with username ad\xyz (domain\username).

Output:

Credential

Recommended Articles

This is a guide to PowerShell Move-Item. Here we discuss the parameters of PowerShell Move-Item with the appropriate examples. You can also go through our other related articles to learn more –

  1. What is PowerShell
  2. PowerShell Variables
  3. PowerShell String Functions
  4. How To Install PowerShell
  5. Guide to PowerShell Date

Programming Languages Training (41 Courses, 13+ Projects)

41 Online Courses

13 Hands-on Projects

322+ Hours

Verifiable Certificate of Completion

Lifetime Access

4 Quizzes with Solutions

Learn More

1 Shares
Share
Tweet
Share
Primary Sidebar
PowerShell Tutorial
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Basics
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Special Offer - Programming Languages Training (41 Courses, 13+ Projects) Learn More