相关疑难解决方法(0)

我可以将Powershell 4与Powershell 3并排安装吗?

我的盒子上安装了Powershell 3.

我需要使用Powershell 4测试一些脚本,但我想继续运行一些在Powershell 3下测试的脚本,我不想通过安装Powershell 4来破坏某些东西.

问题:尽管我已安装Powershell 4,是否可以在Powershell版本3下打开Powershell会话(如果需要,甚至可以打开2个)?

powershell powershell-2.0 powershell-3.0

3
推荐指数
1
解决办法
3291
查看次数

为什么在 PowerShell 中,当尝试调用模块中的 cmdlet 时,会自动导入已安装的模块?

我是 PowerShell 的新手。我在导入模块时遇到了问题。当我尝试在该模块中调用 cmdlet 时,似乎会自动导入已安装的模块。

那是:

  1. 如果已经安装了某个模块,例如Install-Module -Name PSscriptAnalyzer
  2. 不要导入它。检查是否已导入:
    Get-Module PSScriptAnalyzer
    # Show nothing
    
    Run Code Online (Sandbox Code Playgroud)
  3. 尝试在以下位置使用 cmdlet PSScriptAnalyzer
    Invoke-ScriptAnalyzer -Path ./ -Recurse
    # Ignore any info
    
    Run Code Online (Sandbox Code Playgroud)
  4. 然后模块PSScriptAnalyzer将自动导入:
    Get-Module PSScriptAnalyzer
    
    Run Code Online (Sandbox Code Playgroud) 显示如下:
    ModuleType Version    PreRelease Name                                
    ExportedCommands
    ---------- -------    ---------- ----                                ----------------
    Script     1.21.0                PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke-ScriptAnalyzer}
    
    Run Code Online (Sandbox Code Playgroud)

为什么模块只要导入了就会自动导入呢ExportedCommands?它的机制是什么?如果是这样,那么Remove-Module在一般使用场景中似乎就没有多大意义了。

提前致谢。

powershell powershell-7.3

2
推荐指数
1
解决办法
142
查看次数