Search code examples
windowspowershellservicetask

PS script to copy data to external file share location


Scenario:

Site to Site VPN is configured with my network and with a remote Data centre and there is no AD Trust

On a daily basis, I need to copy the data from my server folder to remote file share location

For example:

Platform: Windows 2008 Server folder : D:\Data Remote file share location: \1.2.3.4\Data

For remote file share location, they have different domain (for example username: xyz\user1)

How can I have a script where the data generated in our server folder (D:\Data) can be replicated to remote file share location using their credentials on a daily basis?

I'm confused with the step where how I can pass the 3rd party credentials to copy the data to their location as AD Trust is not configured.

Thanks in Advance.


Solution

  • You can use something like $cred = Get-Credential to create a variable that will store the credential in a PSCredential object.

    Then when you call on it later you can just use $cred instead of signing in.

    This will cause the script to prompt for domain credentials each time the script is run, and then use those when moving the files. I have used a simple cmdlet below and separated out the credential variable for readability.

    Get-CimInstance Win32_DiskDrive -ComputerName Server01 -Credential $cred