在网络共享上移动文件

发布于 2024-10-13 02:39:42 字数 1038 浏览 7 评论 0原文

我想通过 powershell 自动执行许多日常任务。我们的流程之一是在下班后对桌面进行映像。此操作完成后,需要将图像文件从服务器硬盘移至网络驱动器。我正在编写一个应用程序作为服务在我的机器上运行,它将调用 powershell 脚本并清除所有内容,仅在出现问题时提醒我。

我在服务器上为脚本设置了一个目录。如果我从服务器调用我的脚本 FileCopy.ps1,它工作正常:

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

但是,在我的 .Net 应用程序中,我从本地计算机调用该脚本:

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

不起作用。这是因为它将 C:\scripts 视为位于本地计算机上。所以,我改变它:

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

不起作用。我在脚本中添加了另一行:

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

它仍然不复制文件,但它确实返回服务器上脚本目录的内容。

因此,我返回服务器并使用 UNC 路径运行脚本 - powershell 返回错误

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

这似乎是问题的根源。知道我该如何解决这个问题吗?我以管理员身份登录服务器。

I want to automate many of my daily tasks via powershell. One process that we have is imaging desktops after hours. Once this operation is complete, the image files need to be moved off the server hard drives to a network drive. I'm writing an app to run as a service on my machine that will call the powershell script and knock everything out, alerting me only when there is a problem.

I set up a 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 app, I call the script from my local machine:

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

Doesn't work. That's 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

Doesn't 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 doesn't copy the file, but it does return the contents of the scripts directory on the server.

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

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

That seems to be the root of the problem. Any idea how I can get around this? I'm logged onto the server as an admin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月染过的梦 2024-10-20 02:39:42

以管理员身份运行脚本与网络共享 IIRC 无关。默认共享权限仅允许读取。需要更新这些权限以允许写入共享。

仅供参考,如果您使用 net share 在 Windows 7 上创建共享,您将需要使用 /grant:,CHANGE 将这些权限授予用户。

Running the script as admin doesn't matter with network shares IIRC. The default share permission allow only reading. Those perms need to be updated to allow writing to the share.

FYI if you're using net share to create the shares on Windows 7 you will need to use the /grant:<users>,CHANGE to grant those permissions to a user.

影子是时光的心 2024-10-20 02:39:42

我使用的是 Server 2003 R2。管理员在“安全”选项卡下拥有完全访问权限,但我转到“共享”选项卡、“权限”,并且“每个人”都设置为“读取”访问权限。我将管理员和我自己添加为完全控制,现在生活很好!

I'm on Server 2003 R2. Administrator had full access under the Security tab, but I went to the sharing tab, permissions, and Everyone was set to Read access. I added admin and myself as Full Control, now life is good!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文