What is the PowerShell syntax?


Haydon

Well-known member
Member
VIP
Local time
2:05 AM
Posts
1,113
OS
Windows 10 Pro
What is the syntax of the Copy-Item cmdlet to copy/mirror the C:\Users\Me folder on an external SSD folder D:\MeMirror ?
 

My Computer

System One

  • OS
    Windows 10 Pro

cereberus

Well-known member
Pro User
VIP
Local time
7:05 AM
Posts
3,010
OS
Windows 10 Pro + others in VHDs
What is the syntax of the Copy-Item cmdlet to copy/mirror the C:\Users\Me folder on an external SSD folder D:\MeMirror ?
I rarely say this but google it!

The syntax of such cmdlets is often quite complicated and too much for users to summarise in a post.

Here I did some leg-work by googling "copy-item cmdlet" for you.

 

My Computer

System One

  • OS
    Windows 10 Pro + others in VHDs
    Computer type
    Laptop
    Manufacturer/Model
    ASUS Vivobook 14
    CPU
    I7
    Motherboard
    Yep, Laptop has one.
    Memory
    16 GB
    Graphics Card(s)
    Integrated Intel Iris XE
    Sound Card
    Realtek built in
    Monitor(s) Displays
    N/A
    Screen Resolution
    1920x1080
    Hard Drives
    1 TB Optane NVME SSD, 1 TB NVME SSD
    PSU
    Yep, got one
    Case
    Yep, got one
    Cooling
    Stella Artois
    Keyboard
    Built in
    Mouse
    Bluetooth , wired
    Internet Speed
    72 Mb/s :-(
    Browser
    Edge mostly
    Antivirus
    Defender
    Other Info
    TPM 2.0

Haydon

Well-known member
Member
VIP
Thread Starter
Local time
2:05 AM
Posts
1,113
OS
Windows 10 Pro
@cerberus Thanks, I should have known that there was a pertinent microsoft docs item (I got confused by some 'ultimate guide', the microsoft docs item is much, much clearer)

After trying out some cmdlets, the most purposeful for me is

Copy-Item -Path "C:\Users\Me\*" -Destination "D:\MeCopy" -Recurse

The cmdlet needs to be run twice, the first run is to establish the directory. It creates a copy that also captures additions and changes to files in subsequent runs, but it does not delete files, i.e. it is not a true mirror. It also creates the Junctions inside the My Documents folder (My Music, My Pictures, My Videos) but the subfolders are empty, i.e. PowerShell is smart enough not to duplicate, so there is no need for any exclusion (which does not appear to be possible either)

I am still testing things :D
 

My Computer

System One

  • OS
    Windows 10 Pro

Haydon

Well-known member
Member
VIP
Thread Starter
Local time
2:05 AM
Posts
1,113
OS
Windows 10 Pro
The cmdlet below preserves the time stamps of the files, but not the time stamps of the folders.

Copy-Item -Path "C:\Users\Me\*" -Destination "D:\MeCopy" -Recurse

How do I preserve the time stamps of the folders?
 

My Computer

System One

  • OS
    Windows 10 Pro

Latest Support Threads

Top Bottom