Monday, July 11, 2016

Copying files and folders to a remote folder using PowerShell

I have been switching many of scripts from using command-line operations over to PowerShell in recent weeks and one of the operations I had been doing earlier was using the "net use" command to map drives to remote shares on servers before copying them over using Robocopy.

However, I did not really need to use the "net use" command since it was just part of a background process and the drive letter could be deleted immediately after the copy operation was completed so I began searching for PowerShell alternatives.

I found just such an alternative using the "New-PSDrive" command:

https://technet.microsoft.com/en-us/library/hh849829.aspx

https://technet.microsoft.com/en-us/library/ee176915.aspx

Once I understood exactly how to use this PowerShell cmdlet, I was able to compose the following PowerShell script:

No comments:

Post a Comment