-1

I have a simple script which only prints "hello" to the screen.

When I run it from my desktop (for example) - it's working

When I run it from a specific folder under, c:\specific_folder it opens the "How do you want to open this file" window and even after I choose "Windows Powershell" it just keep popping up and script never executed..

I'm using Powershell version 5.1 I checked the permissions on folder properties and give everyone a full control but no change..

EDIT: the script is:

Write-output "Hello"
pause

I run it by double clicking it (manually).

Can you help? Thanks

Noam
  • 1,640
  • 4
  • 26
  • 55
  • Can you include the script & how are you trying to run it? – Gareth Lyons Oct 30 '17 at 17:54
  • @GarethLyons - done. – Noam Oct 30 '17 at 17:59
  • right click select "open with", "choose another App", select Powershell, Check "Always use this app to open PS1 files", Click OK. Also add a pause in the script so it keeps the window open – ArcSet Oct 30 '17 at 18:09
  • 1
    @ArcSet That's a very bad practice and also requires changing executionpolicy. – Maximilian Burszley Oct 30 '17 at 18:16
  • Some discussion here: https://stackoverflow.com/questions/10137146/is-there-any-way-to-make-powershell-script-work-by-double-clicking-ps1-file – Gareth Lyons Oct 30 '17 at 18:28
  • @TheIncorrigible1 I agree but thats what he asked for – ArcSet Oct 30 '17 at 18:30
  • Possible duplicate of [Is there any way to make powershell script work by double clicking .ps1 file?](https://stackoverflow.com/questions/10137146/is-there-any-way-to-make-powershell-script-work-by-double-clicking-ps1-file) – TessellatingHeckler Oct 30 '17 at 18:39
  • @ArcSet this isn't the case, I know hot to make it use the powershell as default but for some reason it isnt working in a specific directory, I think it is some permission related issue – Noam Oct 31 '17 at 07:44

1 Answers1

0

If you are double clicking it, it might be executing and instantly closing as the script has finished.

You might want to add something like read-host or sleep(1) to the end just to be able to confirm the script is working

Shadowzee
  • 537
  • 3
  • 15
  • This is not the problem, I added a `pause` just to make sure.. If I try to run in 2 different folders (by double clicking it) then in one folder it works and in the second folder it just keep popping the "How do you want to open" window.. I thing it is a permission related issue.. – Noam Oct 31 '17 at 07:46