Powershell script: Copy-Item fails when -Destination is UNC with access denied

Hello, guys!
I’m trying to execute Powershell script that copies one file from local drive to network location

$src = C:\file.txt
$dst = \\Share\file.txt
Copy-Item $src -Destination $dst

but it fails with ‘Access denied’ error

When i executed this script localy from Powershell all went good
Share folder permisions are set to All/FullControl for both Share and NTFS security options.
I think the problem may be in SYSTEM user from witch Tentacle executing Powershell script

Can you help me with this?

Also tried to mount PSDrive and failed again

New-PSDrive : Drive root “\\Share” does not exi
Error 18:00:07
st or it’s not a folder.
Error 18:00:07
At C:\Windows\system32\config\systemprofile\AppData\Local\Tentacle\Temp\d1d3fcb
Error 18:00:07
d-a56c-4c26-9204-fb3f7f6366a7.ps1:11 char:12
Error 18:00:07

  • New-PSDrive <<<< -Name X -PSProvider FileSystem -Root \\Share
    Error 18:00:07
    • CategoryInfo : ReadError: (X:PSDriveInfo) [New-PSDrive], IOExce
      Error 18:00:07
      Error 18:00:07
    • FullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.New
      Error 18:00:07


Thanks for getting in touch! The service user that Octopus runs under would not have the permissions to perform the tasks you are after.
You can change the user that tentacle runs under for these scenarios:

Let me know how that goes!

hello! thanks for the advice now copy-item works fine, but after i changed the RunAs user the script stucks at this step:

Unzip archive.zip

echo “Unzip archive…”
$shell_app = New-Object -com shell.application
$s_zip = $shell_app.namespace($zip)
$s_unzip = $shell_app.namespace($unzip)

when i logon to machine with creds thst i set as RunAs for Tentacle and run this script localy from Powershell it works fine

resolved this issue by using 7zip CLI to unzip archive