locked
Powershell Execution Problem RRS feed

  • Question

  • I am trying to make a simple powershell script that the users can double click on to copy files to their project. 

    I am using this very simple line of code in a file called "00 Administration.ps1". 

    Copy-Item "C:\Temp\Folder" -Destination "C:\Temp\Folder Renamed" -Recurse

    I can run it just fine via the command line interface and the ISE with no issues, but when I double click on the file I get an error message that flashes very briefly. The "C:\Temp\00" that the error message is referring to is the name of the script. When I double click the file it says that it is not recognized as the name of a cmdlet, function, script, or operable program. Am I wrong in thinking that PS1 files can be double clicked on to run? 

    I have used powershell to manage services, sites, and servers for years, but I haven't ever created a script to be double clicked on, so I may be assuming this is possible and it may not be. 

    Thanks

    Monday, September 10, 2018 9:23 PM

Answers

All replies

  • Hi,

    Try without having a space in the name of your script:

    00 Administration.ps1 -> 00Administration.ps1

    Best regards,
    Leon


    Blog: https://thesystemcenterblog.com LinkedIn:

    • Marked as answer by RussinAustin Monday, September 10, 2018 9:48 PM
    Monday, September 10, 2018 9:31 PM
  • Yup....That did it! I never knew it had that limitation. 
    Monday, September 10, 2018 9:41 PM
  • By default, Windows should open .ps1 files with Notepad. Double clicking it should not result in running a PowerShell script (by default) anyway. Neither should there be any issues if you right mouse click a script that contains spaces and click 'Run with PowerShell', this issue only occurs when you 'open it with PowerShell', which means you have probably set PowerShell as the default program to open .ps1 files with.

    Monday, September 10, 2018 9:59 PM