Jacob L
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\copyfro mFTP.ps1 }
Access is denied
+ CategoryInfo : PermissionDenied: (\\wmvddaxapp10\..._2017-0 3-06.txt:S tring) [Move-Item], UnauthorizedAccessExceptio n
+ FullyQualifiedErrorId : MoveItemUnauthorizedAccess Error,Micr osoft.Powe rShell.Com mands.Move ItemComman d
+ PSComputerName : wmvddaxapp10
Access is denied
+ CategoryInfo : PermissionDenied: (\\wmvddaxapp10\...50_2424 8442.xml:S tring) [Move-Item], UnauthorizedAccessExceptio n
+ FullyQualifiedErrorId : MoveItemUnauthorizedAccess Error,Micr osoft.Powe rShell.Com mands.Move ItemComman d
+ PSComputerName : wmvddaxapp10
Access is denied
+ CategoryInfo : PermissionDenied: (\\wmvddaxapp10\...R_Recei vers.txt:S tring) [Move-Item], UnauthorizedAccessExceptio n
+ FullyQualifiedErrorId : MoveItemUnauthorizedAccess Error,Micr osoft.Powe rShell.Com mands.Move ItemComman d
+ PSComputerName : wmvddaxapp10
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\copyfro
Access is denied
+ CategoryInfo : PermissionDenied: (\\wmvddaxapp10\..._2017-0
+ FullyQualifiedErrorId : MoveItemUnauthorizedAccess
+ PSComputerName : wmvddaxapp10
Access is denied
+ CategoryInfo : PermissionDenied: (\\wmvddaxapp10\...50_2424
+ FullyQualifiedErrorId : MoveItemUnauthorizedAccess
+ PSComputerName : wmvddaxapp10
Access is denied
+ CategoryInfo : PermissionDenied: (\\wmvddaxapp10\...R_Recei
+ FullyQualifiedErrorId : MoveItemUnauthorizedAccess
+ PSComputerName : wmvddaxapp10
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\copyfro mFTP.ps1 }
Do all computers have D:\NCR\DAX\Scripts\copyfro mFTP.ps1 or is that the local file?
Invoke-Command -ComputerName wmvddaxapp10 -ScriptBlock { \\NCR\DAX\Scripts\copyfrom FTP.ps1 } ??
Note: ftp.ps1 is not a link but the EE editor thinks it is
Do all computers have D:\NCR\DAX\Scripts\copyfro
Invoke-Command -ComputerName wmvddaxapp10 -ScriptBlock { \\NCR\DAX\Scripts\copyfrom
Note: ftp.ps1 is not a link but the EE editor thinks it is
david, you can use
... without the space : i did not manage to nest them ;)
[code]FTP.com[ /code]
... without the space : i did not manage to nest them ;)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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)
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.
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.