What is the PowerShell syntax?


Haydon

Well-known member
Power User
VIP
Local time
10:59 PM
Posts
1,990
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
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 11 Pro + Win11 Canary VM.
    Computer type
    Laptop
    Manufacturer/Model
    ASUS Zenbook 14
    CPU
    I9 13th gen i9-13900H 2.60 GHZ
    Motherboard
    Yep, Laptop has one.
    Memory
    16 GB soldered
    Graphics Card(s)
    Integrated Intel Iris XE
    Sound Card
    Realtek built in
    Monitor(s) Displays
    laptop OLED screen
    Screen Resolution
    2880x1800 touchscreen
    Hard Drives
    1 TB NVME SSD (only weakness is only one slot)
    PSU
    Internal + 65W thunderbolt USB4 charger
    Case
    Yep, got one
    Cooling
    Stella Artois (UK pint cans - 568 ml) - extra cost.
    Keyboard
    Built in UK keybd
    Mouse
    Bluetooth , wireless dongled, wired
    Internet Speed
    900 mbs (ethernet), wifi 6 typical 350-450 mb/s both up and down
    Browser
    Edge
    Antivirus
    Defender
    Other Info
    TPM 2.0, 2xUSB4 thunderbolt, 1xUsb3 (usb a), 1xUsb-c, hdmi out, 3.5 mm audio out/in combo, ASUS backlit trackpad (inc. switchable number pad)

    Macrium Reflect Home V8
    Office 365 Family (6 users each 1TB onedrive space)
    Hyper-V (a vm runs almost as fast as my older laptop)
@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
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

Back
Top Bottom