[英]Call PowerShell script PS1 from another PS1 script inside Powershell ISE
[英]How can I open a ps1 script in Powershell ISE from the command line?
我試圖弄清楚如何使用 $psISE 對象在 PS ISE 中打開 ps1 腳本(或任何文件)。
如何從 PS ISE 本身的命令行打開 PS ISE 中的文檔選項卡(不使用文件 > 打開)?
ps編輯文件名
Windows 7 中的 PowerShell 2.0,PSEdit 不起作用。 使用“ise”,它是powershell_ise.exe
的別名。
ex. ise .\myscript.ps1
新標簽:
$tab = $psISE.PowerShellTabs.Add()
將腳本文件加載到新選項卡:
$tab.Files.Add("full_path_to_script_file.ps1")
以編程方式,這有效:
$psISE.CurrentPowerShellTab.Files.Add("$pwd\foo.ps1")
這本質上是 PSEdit 函數使用的。 要查看此執行:
Get-Command PSEdit | Format-List *
我使用了 psedit 命令並允許來自管道的輸入
Function psedit {
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]$filenames)
foreach ($filename in $filenames)
{
dir $filename | where {!$_.PSIsContainer} | %{
$psISE.CurrentPowerShellTab.Files.Add($_.FullName) > $null
}
}
}
這讓我可以做這樣的事情
7 > ls test*.ps1 | psedit
我發現這在處理模塊時很有用,並且我在一個目錄中有幾個腳本
安迪
值得注意的是,在Windows 2008 R2中,PowerShell ISE是需要通過服務器管理器安裝的操作系統功能,默認情況下不會安裝。
它是默認安裝在Windows Server 2012中,但因為我沒有其他相關的線程找到這個信息,我認為這是值得一提的這里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.