Created
July 24, 2022 13:18
-
-
Save negatendo/cd5dae69617897e939893367c2b87c36 to your computer and use it in GitHub Desktop.
example usage of PowerShell and robocopy to mirror a network drive to your local machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$include_sources = @('X:','U:','V":','T:','S:','R:','Q:') | |
$dest_drive = "E:\" | |
$robocopy_args = "/MIR /V /MT:16" | |
$network_drive_providers = Get-WmiObject -ClassName Win32_MappedLogicalDisk | Select Name,ProviderName | |
foreach ( $provider in $network_drive_providers ) | |
{ | |
$name = $provider.Name | |
$provider_name = $provider.ProviderName | |
if ( $include_sources.Contains($name) ) | |
{ | |
$dest_dir = $provider_name -split "\\" | |
$command = "robocopy "+$provider_name+" "+$dest_drive+$dest_dir[-1]+" "+$robocopy_args | |
Invoke-Expression $command | |
} | |
} | |
Read-Host -Prompt "Press Enter to exit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment