开发者

Powershell script to map to network drive and download files

I am a newbie to powershell. I want to write a script to do the follo开发者_运维技巧wing

Check if I have mapped to a network drive If not, map to it Once mapped, check the files in 4 folders at a path on the network drive If the files are newer to those I compare to on a local drive, copy them ie. only copy new/updated files

Any help with this would be great as I need a starting position to take on this.


You can use net use to determine if the drive is mapped or not:

net use s:
if ($LastExitCode -ne 0)
{
    net use s: \\server\share
}

$folders = @{local = 'c:\path1';remote='s:\path1'},
           @{local = 'c:\path2';remote='s:\path2'}
$folders | Foreach {xcopy $_.remote $_.local /E /C /H /R /Y /D /I}

Don't forget the existing console tools tend to work just fine in PowerShell and sometimes are the easiest way to get the job done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜