Moving files across network resources

I want to automate many of my daily tasks through powershell. One process that we have is working with desktops through the clock. Once this operation is completed, image files should be transferred from the server’s hard drives to the network drive. I am writing an application to run as a service on my machine, which will call powershell script and kill everything, warning me only in case of a problem.

I installed the directory on the server for scripts. It works fine if I call my script, FileCopy.ps1, from the server:

copy-item C:\scripts\myFile1.txt -destination C:\scripts\myFile2.txt

However, in my .Net application, I call a script from my local machine:

RunScript(LoadScript(@"\\Server\ServerShare\FileCopy.ps1")); 

Does not work. This is because it sees C: \ scripts as being on the local machine. So I change it:

copy-item \\Server\ServerShare\myFile1.txt -destination \\Server\ServerShare\myFile2.txt

Does not work. I add another line to the script:

copy-item \\Server\ServerShare\myFile1.txt -destination \\Server\ServerShare\myFile2.txt
get-childitem \\Server\ServerShare | format-table name

It still does not copy the file, but it does returns the contents of the script directory on the server.

So, I return to the server and run the script with UNC paths in place - powershell returns an error

Copy-Item : Access to the path '\\Server\ServerPath\myFile2.txt' is denied.

This seems to be the root of the problem. Any idea how I can get around this? I am registered on the server as an administrator.

+3
source share
2 answers

Running the script as the administrator does not matter with the IIRC network resources. The default resolution is read-only. These perms need to be updated to allow writing to the share.

FYI, net share Windows 7, /grant:<users>,CHANGE, .

+9

2003 R2. "", " ", "" "" " ". , !

+2

Source: https://habr.com/ru/post/1786775/


All Articles