Powershell script runs locally but not remotely

I have a powershell script that simply copies files from one server to multiple other servers. runs fine when i loggin to the server and run it. but does nothing when i try to execute it remotely through an application.

ive tried putting this at the beginning of the script.
powershell.exe Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy AllSigned -Force

also tried
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

any help greatly appreciated.

Not sure if this helps but as i am troubleshooting i tried to invoke-command from a remote server and get following error.
PS C:\Windows\system32> Invoke-Command -ComputerName wmvddaxapp10 -ScriptBlock { D:\NCR\DAX\Scripts\copyfromFTP.ps1 }
Access is denied
    + CategoryInfo          : PermissionDenied: (\\wmvddaxapp10\..._2017-03-06.txt:String) [Move-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : MoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.MoveItemCommand
    + PSComputerName        : wmvddaxapp10
 
Access is denied
    + CategoryInfo          : PermissionDenied: (\\wmvddaxapp10\...50_24248442.xml:String) [Move-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : MoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.MoveItemCommand
    + PSComputerName        : wmvddaxapp10
 
Access is denied
    + CategoryInfo          : PermissionDenied: (\\wmvddaxapp10\...R_Receivers.txt:String) [Move-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : MoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.MoveItemCommand
    + PSComputerName        : wmvddaxapp10
Jacob LepleyBusiness Systems Programming AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

skullnobrainsCommented:
in windows there is a difference between the network user and the loggedon user. chances are you are not setting the network user when using invoke-command in that way. ( aka your user has no access to any network resource on the remote computer )

i have no idea if invoke-command can set the network user but either that's in the help, or you can alternatively use psexec which does when you connect using "-u user". you can obviously use the currently logged on user.
0
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
i was just running the invoke command as a test. The script i am calling remotely through a 3rd party application where i just type in the name of the script i want it to run. There is a specific user that the application uses. Was trying to avoid using the credentials of a specific user. I have the same script as a batch file and runs file. But when i converted it to a powershell script it doesn't execute and unfortunately i am not getting errors either. i am assuming it has to be some kind of permissions issue. Looking for a way to disable or force run it if possible.
0
skullnobrainsCommented:
Was trying to avoid using the credentials of a specific user

afaik you should not be able to access remote resources in that case.

did your batch file work in the same tool ? if so, can we see both scripts ?
0
Webinar: Miercom Evaluates Wi-Fi Security

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom how WatchGuard's Wi-Fi security stacks up against the competition in our upcoming webinar!

David Johnson, CD, MVPOwnerCommented:
Invoke-Command -ComputerName wmvddaxapp10 -ScriptBlock { D:\NCR\DAX\Scripts\copyfromFTP.ps1 }
Do all computers have  D:\NCR\DAX\Scripts\copyfromFTP.ps1 or is that the local file?
Invoke-Command -ComputerName wmvddaxapp10 -ScriptBlock { \\NCR\DAX\Scripts\copyfromFTP.ps1 } ??

Note: ftp.ps1 is not a link but the EE editor thinks it is
0
skullnobrainsCommented:
david, you can use
[code]FTP.com[ /code]

Open in new window


... without the space : i did not manage to nest them ;)
0
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
Yes David all the computers have the script on it because when the application job runs the script it randomly chooses a server to run it from. So technically the script isn't running from a remote server. the application chooses a server to run it on and runs it from that server. I can manually run it from any of the 4 servers. but when the application tries to run it doesn't seem like its executing. It runs off a service account. What i am trying to figure out is if there is a command i need to put in my script that allows any user to run it or if i have to use credentials in the script.
0
skullnobrainsCommented:
It runs off a service account. What i am trying to figure out is if there is a command i need to put in my script that allows any user to run it or if i have to use credentials in the script.

any user can run your script.
but if the user does not have the required privileges, you'll end up with permission denied.

in this case, your service account is not allowed to write/delete/move to \\wmvddaxapp10

usually service accounts cannot access network drives

you need to run your script using the credentials of a user that does have those privileges
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
The service account definitely has access to network drives. The script i had before was a batch script that does the exact same thing. We are trying to switch everything to powershell. Sounds like i need to put the credentials in of the service account into the script
0
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
Starting to think you guys may not be able to help me. I logged into the server as the service account and ran the script just fine. So maybe the issue is in the application that is trying to execute it. Will take suggestions if you still have any.
0
skullnobrainsCommented:
you are probably missing the difference between remotely accessing an account and locally accessing it. in windows there is a difference and that difference exists regarding network access. if either i'm wrong ( in your case ), or you don't get that difference, i'm actually unable to help you... espetially if you don't provide the working batch that works remotely using the exact same tools (including remote logon)
0
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
Thanks for the help. I believe there is an issue running through this 3rd party app. I scheduled a windows task to execute it and it works fine that way.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.