2016-03-20 2 views
5

Bir .bat dosyası var istiyorumPowershell'i .Bat'tan yeni bir pencerede başlat ve konsoldan çıkmadan bir .ps1'i çalıştırma nasıl yapılır?

  • aç YENİ pencerede
  • Ve .ps1 senaryoyu
  • çalıştırmak Ve PowerShell
çıkıp kapanmıyor içinde bir PowerShell konsolu

start powershell.exe -Command "&'D:\MyToolkit\ToolKit.ps1'" 

Ancak powe kapatır:

Benim yarasa dosyası bu hattı vardır komut dosyasını çalıştırdıktan sonra rshell.

Herhangi bir öneri? Teşekkür

Ayrıca
+2

'-dosyadan Powershell -noexit başlamak ... komuta son parametre olmalıdır "D: \ MyToolkit \ ToolKit.ps1"' – Avshalom

+1

teşekkürler! Yaradı! Sonunda koyduğumda işe yaramadı ama daha önce koyduğumda -Commandit çalıştı – pencilCake

cevap

8
start powershell -noexit -file "D:\MyToolkit\ToolKit.ps1" 

,

Değişim bu kadar -File için -Command Bu soruya orijinal poster için, ama yanıt arayan burada karaya olabilir diğerleri için değil sadece

2

gerekenler , yardım sistemi çok yararlı ve sık gözardı gibi görünüyor.

komutunu kullanarak /? veya PowerShell'da get-help ve get-help -full komutlarının her biri yararlıdır.

Bu durumda, çalıştırmak istediğiniz komutun yardımını (powershell) okuyarak kendi sorunuzu yanıtlamış olabilirsiniz.

PowerShell[.exe] [-PSConsoleFile <file> | -Version <version>] 
    [-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive] 
    [-InputFormat {Text | XML}] [-OutputFormat {Text | XML}] 
    [-WindowStyle <style>] [-EncodedCommand <Base64EncodedCommand>] 
    [-File <filePath> <args>] [-ExecutionPolicy <ExecutionPolicy>] 
    [-Command { - | <script-block> [-args <arg-array>] 
        | <string> [<CommandParameters>] } ] 

PowerShell[.exe] -Help | -? | /? 

-NoExit 
    Does not exit after running startup commands. 

... 

-File 
    Runs the specified script in the local scope ("dot-sourced"), so that the 
    functions and variables that the script creates are available in the 
    current session. Enter the script file path and any parameters. 
    File must be the last parameter in the command, because all characters 
    typed after the File parameter name are interpreted 
    as the script file path followed by the script parameters. 

-NoExit - başlatma komutları çalıştırdıktan sonra çıkış yok mu.

-File - ... Dosya