【问题标题】:PowerShell Import-Module script exceptionPowerShell 导入模块脚本异常
【发布时间】:2014-07-02 15:58:39
【问题描述】:

我有一个使用 AD 模块进行某些操作的脚本。

Import-Module ActiveDirectory

$username=$env:username
$computerName=$env:computername

$userProperties = Get-ADUser $username
$departmentOU = ($userProperties.DistinguishedName -split ',OU=')[1]
$officeOU=($userProperties.DistinguishedName -split ',OU=')[2]
$pathOutUser = "C:\Scripts\UsAer_Logger\Output\$officeOU\$departmentOU.txt"

if (Test-Path $pathOutUser) {
    $computerName >> $pathOutUser
} else {
    New-Item $pathOutUser
    $computerName >> $pathOutUser
}

当我尝试在 PowerShell ISE 上运行它时,出现以下异常:

Import-Module : The following error occurred while loading the extended type da
ta file: 
Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Active
Directory\ActiveDirectory.Types.ps1xml : File skipped because it was already pr
esent from "Microsoft.PowerShell".
Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Active
Directory\ActiveDirectory.Types.ps1xml : File skipped because it was already pr
esent from "Microsoft.PowerShell".
Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Active
Directory\ActiveDirectory.Types.ps1xml : File skipped because it was already pr
esent from "Microsoft.PowerShell".
Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Active
Directory\ActiveDirectory.Types.ps1xml : File skipped because it was already pr
esent from "Microsoft.PowerShell".
Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Active
Directory\ActiveDirectory.Types.ps1xml : File skipped because it was already pr
esent from "Microsoft.PowerShell".

我尝试在没有 Import-Module cmdlt 的情况下运行它,但它无法识别 Get-ADUser 命令。如果您能对此有所了解,我将不胜感激!

【问题讨论】:

    标签: windows exception powershell module


    【解决方案1】:

    您可能安装了两个不同的 ActiveDirectory 模块副本。尝试检查您已安装的模块列表:

    Get-Module -list
    

    如果有冲突你应该卸载模块:

    Remove-Module ActiveDirectory
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 2013-08-24
      • 2015-12-21
      相关资源
      最近更新 更多