PowerShell如何清除当前ISE窗口的自定义变量
发布时间:2020-12-15 22:54:17 所属栏目:安全 来源:网络整理
导读:获取所有变量 "@({0})" -f#@()代表一个空的数组((Get-Variable | select -ExpandProperty name | foreach {"‘$_‘"}) -join ",`n") 清理自定义变量 Function Clear-ISEVariable{ [email?protected]( ‘$‘,‘?‘,‘^‘,‘args‘,‘ConfirmPreference‘,‘Co
获取所有变量
"@({0})" -f #@()代表一个空的数组 ((Get-Variable | select -ExpandProperty name | foreach { "‘$_‘" }) -join ",`n") 清理自定义变量 Function Clear-ISEVariable { [email?protected]( ‘$‘,‘?‘,‘^‘,‘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 备注 Clear-ISEVariable函数同样适用于控制台,因为ISE中的自动化变量基本上是兼容控制台的。 每一台机器上的Profile文件可能不尽相同,最安全的方式是先得到自己机器上的自动化变量白名单,更新一下脚本中的集合,然后再运行。 原文 PowerShell删除ISE编辑器中的自定义变量 - PowerShell 中文博客 http://www.pstips.net/clear-isevariable.html 您也可以关注下方的微信公众号获取更多资讯 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |