Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

restart powershell

function Restart-Host
{
    [CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')]
    Param(
        [switch]$AsAdministrator,
        [switch]$Force
    )

    $proc = Get-Process -Id $PID
    $cmdArgs = [Environment]::GetCommandLineArgs() | Select-Object -Skip 1

    $params = @{ FilePath = $proc.Path }
    if ($AsAdministrator) { $params.Verb = 'runas' }
    if ($cmdArgs) { $params.ArgumentList = $cmdArgs }

    if ($Force -or $PSCmdlet.ShouldProcess($proc.Name,"Restart the console"))
    {
        if ($host.Name -eq 'Windows PowerShell ISE Host' -and $psISE.PowerShellTabs.Files.IsSaved -contains $false)
        {
            if ($Force -or $PSCmdlet.ShouldProcess('Unsaved work detected?','Unsaved work detected. Save changes?','Confirm'))
            {
                foreach ($IseTab in $psISE.PowerShellTabs)
                {
                    $IseTab.Files | ForEach-Object {

                        if ($_.IsUntitled -and !$_.IsSaved)
                        {
                            $_.SaveAs($_.FullPath,[System.Text.Encoding]::UTF8)
                        }
                        elseif(!$_.IsSaved)
                        {
                            $_.Save()
                        }
                    }
                }
            }
            else
            {
                foreach ($IseTab in $psISE.PowerShellTabs)
                {
                    $unsavedFiles = $IseTab.Files | Where-Object IsSaved -eq $false
                    $unsavedFiles | ForEach-Object {$IseTab.Files.Remove($_,$true)}
                }
            }
        }

        Start-Process @params
        $proc.CloseMainWindow()
    }
}
Comment

PREVIOUS NEXT
Code Example
Shell :: delete all git ignored files 
Shell :: npm latest version 
Shell :: unzip gzip 
Shell :: pkg_resources.DistributionNotFound: 
Shell :: lldb for mac 
Shell :: download anaconda for jupyter notebook 
Shell :: adavanced 
Shell :: Dedian/Ubuntu Self Host Your Own Website for Free 
Shell :: git list last marge 
Shell :: git how to correct accidental commit of password 
Shell :: forever command 
Shell :: create symbolic links 
Shell :: pinch on linux 
Shell :: What is the login id in putty for ubuntu 
Shell :: git remove before commit 
Shell :: enable synatax hightlighting in nano 
Shell :: enter a number using RANDOM in shell scripting 
Shell :: usedapp install command 
Shell :: ros2 galactic source 
Shell :: find a match: docker-compose-plugin 
Shell :: android studio git upsh unable to read askpass response 
Shell :: upload large file to remote server in linux 
Shell :: delete directory linu x 
Shell :: How to search within a file when displayed with less program 
Shell :: view ip rules linux 
Shell :: Git - graph all commits for repot in terminal and show commit messages one line 
Shell :: npm ldapjs 
Shell :: crontab test run-parts 
Shell :: snap opera mini install ubuntu 
Shell :: column cut linux 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =