I have two servers in a domain and I use the domain administrator account to run a script to scan with YARA some folders. I want to copy the result to SERVER-1. I have in SERVER-1 a shared folder to store the results with read-write permissions to everybody whose name is YARASCAN.
If I run a .ps1 script from SERVER-SCANNED the copy works fine (I have tried also using New-PSDrive)
copyjob.ps1:
#yara scans and created report.log
Copy-Item .\report.log -Destination \\SERVER-1\YARASCAN
If I run the following script (simplified) I get the error "Acces is denied"
$session = New-PSSession -ComputerName SERVER-SCANNED #Don't need credentials as I running as domain admin
Invoke-Command -Session $session -ScriptBlock {
Set-Location "C:\Windows\Temp\yarascan"; .\copyjob.ps1
}
The reasong needing to copy from SERVER-SCANNED to SERVER-1 is because I want to leave the session open while YARA scans, and after finishing the scan, SERVER-SCANNED copies the result back to SERVER-1. This way I can launch the job on several computers in parallel (this is my intention).
Does anybody how to resolve the issue? Thanks.