Hi techies<\/p>\n
I’m new to PS script and need your urgent help.<\/p>\n
My requirement is to copy the data files from my internal server to a remote third party file-share server on a daily basis.(site to site VPN is configured)<\/p>\n
Please see the below script I used.<\/p>\n
$Source = “\\localserver\\Y$\\Test*”
\n$Dest = “\\1.2.3.4\\TestData\\”
\n$Username = “remotedomain\\test.user”
\n$Password = ConvertTo-SecureString ‘password’ -AsPlainText -Force
\n$Credential = New-Object System.Management.Automation.PsCredential ($Username,$Password)
\nNew-PSDrive -Name ‘W’ -PSProvider FileSystem -Root $Dest -Credential $Credential -Persist
\nCopy-Item -Path $Source -Destination \"W:\" -Recurse -passthru
\nRemove-PSDrive W<\/p>\n
The issue I’m facing is, If I add the third party credentials to Windows “Credential manager” and then if I use the below, it will work.<\/p>\n
New-PSDrive -Name ‘W’ -PSProvider FileSystem -Root $Dest -Persist<\/p>\n
But I feel, that is not a best practice and need to pass the credential within New-PSDrive command.<\/p>\n
Please help me to resolve the issue.<\/p>\n
PS version : 4
\nOS: windows 2008R2 standard<\/p>","upvoteCount":2,"answerCount":6,"datePublished":"2021-04-02T09:43:03.000Z","author":{"@type":"Person","name":"spiceuser-71fx7","url":"https://community.spiceworks.com/u/spiceuser-71fx7"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi techies<\/p>\n
I’m new to PS script and need your urgent help.<\/p>\n
My requirement is to copy the data files from my internal server to a remote third party file-share server on a daily basis.(site to site VPN is configured)<\/p>\n
Please see the below script I used.<\/p>\n
$Source = “\\localserver\\Y$\\Test*”
\n$Dest = “\\1.2.3.4\\TestData\\”
\n$Username = “remotedomain\\test.user”
\n$Password = ConvertTo-SecureString ‘password’ -AsPlainText -Force
\n$Credential = New-Object System.Management.Automation.PsCredential ($Username,$Password)
\nNew-PSDrive -Name ‘W’ -PSProvider FileSystem -Root $Dest -Credential $Credential -Persist
\nCopy-Item -Path $Source -Destination \"W:\" -Recurse -passthru
\nRemove-PSDrive W<\/p>\n
The issue I’m facing is, If I add the third party credentials to Windows “Credential manager” and then if I use the below, it will work.<\/p>\n
New-PSDrive -Name ‘W’ -PSProvider FileSystem -Root $Dest -Persist<\/p>\n
But I feel, that is not a best practice and need to pass the credential within New-PSDrive command.<\/p>\n
Please help me to resolve the issue.<\/p>\n
PS version : 4
\nOS: windows 2008R2 standard<\/p>","upvoteCount":2,"datePublished":"2021-04-02T09:43:03.000Z","url":"https://community.spiceworks.com/t/unc-path-new-psdrive-script-with-credential-not-working/795765/1","author":{"@type":"Person","name":"spiceuser-71fx7","url":"https://community.spiceworks.com/u/spiceuser-71fx7"}},{"@type":"Answer","text":"
This is the old school mapped drive method to use a cred to access shares.<\/p>\n
But with Domains, all you need to do is to ensure the logged in domain user (on client machine) have both rights to access the share and rights to read or write to the location on the file server (source) ?<\/p>","upvoteCount":0,"datePublished":"2021-04-02T10:22:40.000Z","url":"https://community.spiceworks.com/t/unc-path-new-psdrive-script-with-credential-not-working/795765/2","author":{"@type":"Person","name":"adrian_ych","url":"https://community.spiceworks.com/u/adrian_ych"}},{"@type":"Answer","text":"
Thanks adrian_ych for the quick response.<\/p>\n
AD Trust is not configured and so both domains (local server & remote 3rd party file-share) are different.
\nFrom local server, we were able to access remote file share with their 3rd party credentials and do copy-paste-delete the files.<\/p>","upvoteCount":0,"datePublished":"2021-04-02T10:37:04.000Z","url":"https://community.spiceworks.com/t/unc-path-new-psdrive-script-with-credential-not-working/795765/3","author":{"@type":"Person","name":"spiceuser-71fx7","url":"https://community.spiceworks.com/u/spiceuser-71fx7"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n