Save and Restore PowerShell ISE opened scripts

Hello,

Thanks to the PowerShell ISE object, you can do some useful things.

Function Save-IseSession{
    [CmdletBinding()]
    Param(
        [Parameter(Position=0)]
        [String]$Path = "$env:tempIse.txt"
    )

    Begin{
    }
    Process{
        $psISE.CurrentPowerShellTab.Files | % {$_.SaveAs($_.FullPath)}
        "ise ""$($psISE.PowerShellTabs.Files.FullPath -join',')""" | Out-File -Encoding utf8 -FilePath $Path
    }
    End{
    }
}
Function Restore-IseSession{
    [CmdletBinding()]
    Param(
        [Parameter(Position=0)]
        [String]$Path = "$env:tempIse.txt"
    )

    Begin{
    }
    Process{
        Invoke-Expression (Get-Content $Path)
    }
    End{
    }
}

Those two functions allow you to save and restore your ISE opened PowerShell scripts. You need to add those lines to your PowerShell profile to use it anytime you need it :

#Profile Folder 
($env:psmodulepath -split ';')[0]
#Profile file name
($profile -split "")[-1]
#All profiles informations
$PROFILE | select *

 

0 thoughts on “Save and Restore PowerShell ISE opened scripts

  1. Pingback: Save and Restore PowerShell ISE opened scripts - Addon - It For DummiesIt For Dummies

  2. Pingback: Save and restore ISE session path and opened files enhanced – Thomas Prud'homme

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.