Link to home
Start Free TrialLog in
Avatar of Jacob L
Jacob LFlag for United States of America

asked on

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
Avatar of skullnobrains
skullnobrains

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.
Avatar of Jacob L

ASKER

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 ?
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 ;)
Avatar of Jacob L

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jacob L

ASKER

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
Avatar of Jacob L

ASKER

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)
Avatar of Jacob L

ASKER

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.