首页 > 解决方案 > 添加“获取模块 | 移除模块;Clear-Host' 到包含的 PowerShell 代码

问题描述

Stack Overflow 上的某个人分享了以下 PowerShell 代码。我的代码在我修改的脚本中工作。我想Get-Module | Remove-Module; Clear-Host向它添加功能。

并且在运行脚本后添加这些实际上会有所帮助还是会产生任何不良影响?

我是 Stack Overflow 上的新手,没有评论代码所在线程的声誉。所以我提出了一个新问题。

### Start of script (store list of existing variable names)
$ExistingVariables = Get-Variable | Select-Object -ExpandProperty Name
### End of script (remove new variables)
$NewVariables = Get-Variable | Select-Object -ExpandProperty Name | Where-Object {$ExistingVariables -notcontains $_ -and $_ -ne "ExistingVariables"}
if ($NewVariables)
    {
    Write-Host "Removing the following variables:`n`n$NewVariables"
    Remove-Variable $NewVariables
    }
else
    {
    Write-Host "No new variables to remove!"
    }

标签: powershell

解决方案


推荐阅读