'.ps1 script dont run at double click [duplicate]

i have a script to run and he works fine when i use that on PowerShell ISE, but i need to run at .ps1 file (double clicking) and when i try this, hothing happen... the powershell's window opens but my script dont run.

my code is:

$path = "W:\Processos\Integracao\Titulos Carrefour"
$path2 = "\\fileserver\departamentos$\Matriz\Titulos Carrefour" 
    
    
Set-Location $path
        
        
Get-ChildItem -Path "$path2\*.csv" -Recurse | Move-Item -Destination $path -Force 
        
        
Start-Process 'winscp.com' -ArgumentList /script=envio.scp -Wait


Solution 1:[1]

You can run .ps1 files by right clicking and selecting "Run with PowerShell". If you want to run PowerShell scripts by double clicking, you can create a shortcut:

On Windows,

  1. Right click in your file explorer and create a shortcut
  2. When it asks for location, type: powershell.exe -F "pathofscript". So if your script is located in C:\asdf\hello.ps1, you would type:
    powershell.exe -F "C:\asdf\hello.ps1"

Now you have a shortcut that will run your script when double clicked.

Note: If you move your .ps1 script somewhere else, you'll need to update the shortcut to reflect that.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mklement0