Set-StrictMode 错误 powershell 7 或正常行为
Set-StrictMode bug powershell 7 or normal behavior
希望你能给我解释一下。我有一个脚本来扫描 AD 中的计算机对象。我刚开始使用 powershell 7。
部分脚本如下:
$ErrorActionPreference = "Stop"
Set-StrictMode -Version "Latest"
$adComputerCollection = Get-ADComputer -Filter { OperatingSystem -like "*Windows Server*" }
使用 powershell 7 时出现以下错误:
Get-ADComputer: The 'Get-ADComputer' command was found in the module 'ActiveDirectory', but the module could not be loaded. For more information, run 'Import-Module ActiveDirectory'.
好的,没问题,我只是添加了导入模块,我的脚本如下:
$ErrorActionPreference = "Stop"
Set-StrictMode -Version "Latest"
Import-Module "ActiveDirectory"
$adComputerCollection = Get-ADComputer -Filter { OperatingSystem -like "*Windows Server*" }
然后在导入模块 activeDirectory 时出现以下错误:
Get-PSSession: The remote session with the name WinPSCompatSession is not available.
这是正常现象吗。使用 powershell 5.1 我没有这个问题。我可以在获取广告集合后通过设置严格模式来解决此问题。有人可以向我解释这种行为吗?
我的 psversiontable 是:
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
activedirectory 模块在 "remote" PSSession 中加载到名为 WinPSCompatSession 的本地主机。该模块实际上不是运行 PS 7,而是5.1。
这可能就是您看到错误的原因。
希望你能给我解释一下。我有一个脚本来扫描 AD 中的计算机对象。我刚开始使用 powershell 7。
部分脚本如下:
$ErrorActionPreference = "Stop"
Set-StrictMode -Version "Latest"
$adComputerCollection = Get-ADComputer -Filter { OperatingSystem -like "*Windows Server*" }
使用 powershell 7 时出现以下错误:
Get-ADComputer: The 'Get-ADComputer' command was found in the module 'ActiveDirectory', but the module could not be loaded. For more information, run 'Import-Module ActiveDirectory'.
好的,没问题,我只是添加了导入模块,我的脚本如下:
$ErrorActionPreference = "Stop"
Set-StrictMode -Version "Latest"
Import-Module "ActiveDirectory"
$adComputerCollection = Get-ADComputer -Filter { OperatingSystem -like "*Windows Server*" }
然后在导入模块 activeDirectory 时出现以下错误:
Get-PSSession: The remote session with the name WinPSCompatSession is not available.
这是正常现象吗。使用 powershell 5.1 我没有这个问题。我可以在获取广告集合后通过设置严格模式来解决此问题。有人可以向我解释这种行为吗?
我的 psversiontable 是:
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
activedirectory 模块在 "remote" PSSession 中加载到名为 WinPSCompatSession 的本地主机。该模块实际上不是运行 PS 7,而是5.1。
这可能就是您看到错误的原因。