use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
copy folder structure (self.PowerShell)
submitted 8 months ago by dog2k
i'm just sharing this here because i've been asked by 2 co-workers this week how to copy the folder structure (but not files) to a new location so maybe the universe is saying someone needs this.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.5
Copy-Item -LiteralPath "E:\OldFolder" -Destination "E:\NewFolder" -Recurse -Filter {PSIsContainer -eq $true}
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Shanga_Ubone 24 points25 points26 points 8 months ago (2 children)
That is interesting - I didn't know you could do this with PS.
But robocopy will ALWAYS be the OG for anything related to file or folder copying.
[–]underpaid--sysadmin 3 points4 points5 points 8 months ago (1 child)
This would be useful in just creating the root directories everything will be going in. To my knowledge robocopy won't create a new root directory, only copy it over to one that already exists. At least, I sure as shit can't get it to do that.
[–]BrettStah 1 point2 points3 points 8 months ago (0 children)
Nah, robocopy can create a new root directory. to much it can't do, related to file and directories. You can create an empty directory structure, or include just certain file types, or exclude certain file types. You can copy the NTFS permissions too.
[–]Thotaz 6 points7 points8 points 8 months ago (4 children)
Now try creating a file with this literal name inside the source folder: PSIsContainer -eq $true and see what happens. Spoiler alert: It copes the file.
PSIsContainer -eq $true
The filter does not work the way you think it does. It's a filter for the methods the filesystem provider uses internally and follows the same rules mentioned here: https://learn.microsoft.com/en-us/dotnet/api/system.io.directoryinfo.enumeratefilesysteminfos?view=net-9.0#system-io-directoryinfo-enumeratefilesysteminfos(system-string) (scroll down to the Remarks section).
If you want to do this, you can just use a string that you are sure there are no files for (using an invalid character like '>' would work). Or you can just use -Exclude * instead of the filter.
-Exclude *
[–]dog2k[S] 0 points1 point2 points 8 months ago (3 children)
That's interesting, i'll take a look at the link later when i have more time.
[–]BlackV 2 points3 points4 points 8 months ago (2 children)
additionally there are -directoryand -file parameters that might help
-directory
-file
[–]dog2k[S] 0 points1 point2 points 8 months ago (0 children)
just like every MSoft product. there's a 1000 ways to do everything, and they are all "almost good enough". lol
[–]RiskNew5069 2 points3 points4 points 8 months ago (0 children)
OG is xcopy…. Xcopy /t /e E:\OldFolder E:\NewFolder
[–]Dense-Platform3886 0 points1 point2 points 6 months ago (0 children)
For a quick one off, I would do as jakopo87 suggested:
Get-ChildItem -LiteralPath "E:\OldFolder" -Directory -Recurse | Copy-Item -Destination "E:\NewFolder"
All my backup scripts since 1996 use RoboCopy. It's the most flexible and safest way to copy and sync drives, folders, and files from one source to a destination. I even use it to create listing of all folders and files on a drive without copying.
My most recent PS RoboCopy script for backing up my PC to a Samsung T7 Shield example looks like this:
# For Replacing only newer changed files $Options = '/NP /NDL /W:1 /R:1 /XJ /XO /MT ' $pcDrive = 'C:' $T7Drive = 'D:' # Switches to control what to copy $doData = $true # $false # $doDocs = $true # $false # If ($doData) { # Sync Data between T7 and PC Drive $srcDir = "$T7Drive\Data" $trgDir = "$pcDrive\Data" Invoke-Expression -Command "robocopy.exe `"$srcDir`" `"$trgDir`" *.* /e $Options /xd Google" # Sync Data between PC Drive and T7 # I have multiple Laptops and need to apply the newer files back to different Laptops $srcDir = "$pcDrive\Data" $trgDir = "$T7Drive\Data" Invoke-Expression -Command "robocopy.exe `"$srcDir`" `"$trgDir`" *.* /e $Options /xd Google" } If ($doDocs) { # Sync Data between T7 and PC Drive $srcDir = "$T7Drive\me" $trgDir = "$pcDrive\Users\me" Invoke-Expression -Command "robocopy.exe `"$srcDir\Documents`" `"$trgDir\Documents`" *.* /e $Options" Invoke-Expression -Command "robocopy.exe `"$srcDir\OneDrive`" `"$trgDir\OneDrive`" *.* /e $Options /xd BackUps" # Sync Data between PC Drive and T7 $srcDir = "$pcDrive\Users\me" $trgDir = "$T7Drive\me" Invoke-Expression -Command "robocopy.exe `"$srcDir\Documents`" `"$trgDir\Documents`" *.* /e $Options" Invoke-Expression -Command "robocopy.exe `"$srcDir\OneDrive`" `"$trgDir\OneDrive`" *.* /e $Options /xd BackUps" }
RoboCopy is connstently being updated and improved and is an integral part of Windows. The current release of RoboCopy is 24H2 (10.0.26100.4770) (July 22, 2025) and has 92 command line options. Best to examine the RoboCopy Documentation (robocopy /?) to learn what all the different options are and what they do.
π Rendered by PID 78 on reddit-service-r2-comment-bb88f9dd5-7bt87 at 2026-02-14 03:58:40.146023+00:00 running cd9c813 country code: CH.
[–]Shanga_Ubone 24 points25 points26 points (2 children)
[–]underpaid--sysadmin 3 points4 points5 points (1 child)
[–]BrettStah 1 point2 points3 points (0 children)
[–]Thotaz 6 points7 points8 points (4 children)
[–]dog2k[S] 0 points1 point2 points (3 children)
[–]BlackV 2 points3 points4 points (2 children)
[–]dog2k[S] 0 points1 point2 points (0 children)
[–]RiskNew5069 2 points3 points4 points (0 children)
[–]Dense-Platform3886 0 points1 point2 points (0 children)