Copy Files Remote
Published: 2024-05-26
$creds = Get-Credential -UserName "{domain_name}\$Env:UserName" -Message "Enter your privileged account details:"
New-PSDrive -Name "AdminShare" -PSProvider "FileSystem" -Root "\\{servername}\c$" -Credential $creds
try {
Copy-Item -Path "$PSScriptRoot\{filename01}.ext" -Destination "AdminShare:\{folder}\{path}" -Force
Copy-Item -Path "$PSScriptRoot\{filename02}.ext" -Destination "AdminShare:\{folder}\{path}" -Force
Copy-Item -Path "$PSScriptRoot\{filename03}.ext" -Destination "AdminShare:\{folder}\{path}" -Force
Write-Host "Files copied."
}
catch {
Write-host -f yellow "Encountered Error:"$_.Exception.Message
}
Remove-PSDrive -Name "AdminShare"