Save and restore ISE session path and opened files enhanced

Hi Guys,

Inspired by the work done by my buddy Emmanuel to save and restore ISE opened scripts, I worked yesterday night to improve a little his job.

Couple of years ago I found Emmanuel’s work interesting so I used it. Yesterday I was wondering if this functions I am using every days could be slightly updated.

Will editing the Save-ISESession function I came with the idea of saving the ISE Session current path. Therefor I needed a way to save the scripts in another way than Emmanuel did.

Here is the edit I came with:

[ps]Function Save-IseSession{
<#
.SYNOPSIS
Describe purpose of "Save-IseSession" in 1-2 sentences.

.DESCRIPTION
Add a more complete description of what the function does.

.PARAMETER Path
Describe parameter -Path.

.EXAMPLE
Save-IseSession -Path Value
Describe what this call does

.NOTES
Place additional notes here.

.LINK
URLs to related sites
The first link is opened by Get-Help -Online Save-IseSession

.INPUTS
List of input types that are accepted by this function.

.OUTPUTS
List of output types produced by this function.
#>
[CmdletBinding()]
Param(
[String]$Path = ("{0}\OneDrive\Documents\PowerShell\Ise\{1}.xml" -f $env:USERPROFILE, $env:COMPUTERNAME)
)

Begin{}
Process{
New-Object -TypeName psobject -Property @{
Pwd = $pwd
Files = $psISE.CurrentPowerShellTab.Files
} | Export-Clixml -Path $Path
}
End{}
}

Function Restore-IseSession{
<#
.SYNOPSIS
Describe purpose of "Restore-IseSession" in 1-2 sentences.

.DESCRIPTION
Add a more complete description of what the function does.

.PARAMETER Path
Describe parameter -Path.

.EXAMPLE
Restore-IseSession -Path Value
Describe what this call does

.NOTES
Place additional notes here.

.LINK
URLs to related sites
The first link is opened by Get-Help -Online Restore-IseSession

.INPUTS
List of input types that are accepted by this function.

.OUTPUTS
List of output types produced by this function.
#>
[CmdletBinding()]
Param(
[String]$Path = ("{0}\OneDrive\Documents\PowerShell\Ise\{1}.xml" -f $env:USERPROFILE, $env:COMPUTERNAME)
)

Begin{}
Process{
$XmlSave = Import-Clixml -Path $Path
Set-Location -Path $XmlSave.Pwd.path
foreach ($file in $XmlSave.Files.FullPath) {
$null = $psISE.CurrentPowerShellTab.Files.Add($file)
}
}
End{}
}[/ps]

I prefered to change the path where the ISE Session is saved, so all my computers ISE Session are saved in my personnal OneDrive (I manly use my OneDrive to store scripts so I can open back a session from a computer to another).

To save both the path and the opened scripts I changed the exporting format to XML instead of TXT with the FullPath of the opened scripts in it.

To be sure that opened scripts can also be restored, I updated the Restore-IseFunction with the new path and the new format.