When PS scripts executes, it is possibly create much user defined variables.

So, sometimes these varibales may confuse us a lot.

Here's a workaound:

Most of the standard variables can be found in System.Management.Automation.SpecialVariables. If you filter out these and a small list of other known variables, you can create a reusable function to get user-defined variables:

function Get-UDVariable {
get-variable | where-object {(@(
"FormatEnumerationLimit",
"MaximumAliasCount",
"MaximumDriveCount",
"MaximumErrorCount",
"MaximumFunctionCount",
"MaximumVariableCount",
"PGHome",
"PGSE",
"PGUICulture",
"PGVersionTable",
"PROFILE",
"PSSessionOption"
) -notcontains $_.name) -and `
(([psobject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') | Where-Object FieldType -eq ([string]) | ForEach-Object GetValue $null)) -notcontains $_.name
}
}

in your script, just use :

Get-UDVariable | Remove-Variable

One more suggestion:

I don't think it will be the best solution to solve problems made by remaining varibales.

When we create varibale in our scripts, we should have a think that what is the proper scope ?

MSDN ref : https://technet.microsoft.com/en-us/library/hh847849.aspx

最新文章

  1. PHP钩子机制
  2. IOS时间传递机制简记
  3. Linux内核中的GPIO系统之(3):pin controller driver代码分析
  4. Code Jam 2008 APAC local onsites Problem C. Millionaire —— 概率DP
  5. 使用Lucene.net提升网站搜索速度整合记录
  6. awk使用入门
  7. Effective Java2读书笔记-类和接口(二)
  8. HDU 3401 Trade(单调队列优化)
  9. 团队作业4——第一次项目冲刺(Alpha版本)2st day
  10. Java课程设计-计算器 郑子杰(201521123021)
  11. Colossus: Successor to the Google File System (GFS)
  12. 2. ELK 之kibana 简介、获取、安装
  13. “玲珑杯”ACM比赛 Round #18---图论你先敲完模板(DP+思维)
  14. 2018-2019-2 网络对抗技术 20165227 Exp2 后门原理与实践
  15. MongoDB索引的种类与使用
  16. eclipse 中使用中文JAVA api文档
  17. Linux下adb的配置
  18. WebService-php- 2(17)
  19. Codeforces Round #416 (Div. 2) A+B
  20. UVa 1349 - Optimal Bus Route Design(二分图最佳完美匹配)

热门文章

  1. C++ ofstream和ifstream
  2. javascript 工作必知(四) 类型转换
  3. English - even though和even if用法解析
  4. 原生js封装table表格操作,获取任意行列td,任意单行单列方法
  5. 调度器(scheduler)
  6. Linux流量监控工具使用总结 - iftop
  7. 浏览器 HTTP 缓存原理分析
  8. 关于微信浏览不能URL传参,URL中的问号被删除
  9. codevs 3013 单词背诵 hash
  10. Groovy在不同JDK版本下的性能差异