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 :: get path of command 
Shell :: xrandr 1366 
Shell :: prevent pushing to master github 
Shell :: ubuntu take screenshot with cursor 
Shell :: remove remote 
Shell :: git push to remote 
Shell :: remove composer package 
Shell :: shell one line for loop 
Shell :: installing rabbitmq on debian 
Shell :: kill k3s 
Shell :: install vscode ubuntu 
Shell :: bash upgrade cmake (From Source) 
Shell :: how to paste in git bash 
Shell :: create new repo 
Shell :: how to set to default terminal in ubunty 
Shell :: install latex 
Shell :: how to mount windows folder on ubuntu 
Shell :: check disk space folders linux 
Shell :: check how many container running or not running in docker 
Shell :: conda command to install folium 
Shell :: git stash example 
Shell :: install flask dockerfile freeze 
Shell :: install simplejwt django 
Shell :: gh clone 
Shell :: supervisord install ubuntu 
Shell :: strapi run command 
Shell :: surge delete project 
Shell :: snap purge 
Shell :: how to remove blank lines in bash 
Shell :: curl post form 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =