Powershell script runs locally but not remotely

Jacob Lepley
Jacob Lepley used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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.
Jacob LepleyBusiness Systems Programming Analyst

Author

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.
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 ?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Top Expert 2016

Commented:
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
david, you can use
[code]FTP.com[ /code]

Open in new window


... without the space : i did not manage to nest them ;)
Jacob LepleyBusiness Systems Programming Analyst

Author

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.
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
Jacob LepleyBusiness Systems Programming Analyst

Author

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
Jacob LepleyBusiness Systems Programming Analyst

Author

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.
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)
Jacob LepleyBusiness Systems Programming Analyst

Author

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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial