Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Invoke-PowerShell {
powershell -nologo
Invoke-PowerShell
}
function Restart-PowerShell {
if ($host.Name -eq 'ConsoleHost') {
exit
}
Write-Warning 'Only usable while in the PowerShell console host'
}
Set-Alias -Name 'reload' -Value 'Restart-PowerShell'
$parentProcessId = (Get-WmiObject Win32_Process -Filter "ProcessId=$PID").ParentProcessId
$parentProcessName = (Get-WmiObject Win32_Process -Filter "ProcessId=$parentProcessId").ProcessName
if ($host.Name -eq 'ConsoleHost') {
if (-not($parentProcessName -eq 'powershell.exe')) {
Invoke-PowerShell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment