Question
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.
Solution
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.
OTHER TIPS
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!!