Skip to content

Instantly share code, notes, and snippets.

@negatendo
Created July 24, 2022 13:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save negatendo/cd5dae69617897e939893367c2b87c36 to your computer and use it in GitHub Desktop.
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
$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