PowerShell导入模块脚本异常

时间:2014-07-02 15:58:39

标签: windows exception powershell module

我有一个脚本,它使用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命令。如果你能对此有所了解,我真的很感激!

1 个答案:

答案 0 :(得分:1)

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

Get-Module -list

如果存在冲突,您应该卸载该模块:

Remove-Module ActiveDirectory