How PowerShell Clears Custom Variables in the Current ISE Window

Keywords: Windows

Get all variables

"@({0})" -f
#@ () Represents an empty array
((Get-Variable  | select -ExpandProperty name | foreach {
"'$_'"
}) -join ",`n")

Clean up custom variables

Function Clear-ISEVariable
{
    $sysVar=@(
    '$',
    '?',
    '^',
    'args',
    'ConfirmPreference',
    'ConsoleFileName',
    'DebugPreference',
    'Error',
    'ErrorActionPreference',
    'ErrorView',
    'ExecutionContext',
    'false',
    'FormatEnumerationLimit',
    'HOME',
    'Host',
    'InformationPreference',
    'input',
    'LASTEXITCODE',
    'MaximumAliasCount',
    'MaximumDriveCount',
    'MaximumErrorCount',
    'MaximumFunctionCount',
    'MaximumHistoryCount',
    'MaximumVariableCount',
    'MyInvocation',
    'NestedPromptLevel',
    'null',
    'OutputEncoding',
    'PID',
    'profile',
    'ProgressPreference',
    'PSBoundParameters',
    'PSCommandPath',
    'PSCulture',
    'PSDefaultParameterValues',
    'PSEmailServer',
    'PSHOME',
    'psISE',
    'PSScriptRoot',
    'PSSessionApplicationName',
    'PSSessionConfigurationName',
    'PSSessionOption',
    'PSUICulture',
    'psUnsupportedConsoleApplications',
    'PSVersionTable',
    'PWD',
    'ShellId',
    'StackTrace',
    'true',
    'VerbosePreference',
    'WarningPreference',
    'WhatIfPreference')

    Get-Variable -Scope 1 | Where-Object {
        $sysVar -notcontains $_.Name
    }  | Remove-Variable -Scope 1 -Force

}
Clear-ISEVariable

Remarks

Clear-ISEVariable functions are also applicable to consoles, because the automation variables in ISE are basically compatible with consoles.
Profile files may be different on each machine. The safest way is to get a whitelist of automated variables on your machine, update the collection in the script, and then run it.

original text

PowerShell deletes the custom variable in the ISE editor - PowerShell Chinese blog http://www.pstips.net/clear-isevariable.html

You can also follow the following Wechat Public Number for more information

Posted by Jeannie109 on Sat, 23 Mar 2019 02:57:53 -0700