alexbazzi
alexbazzi

Reputation: 13

PowerShell Import-Module script exception

I have a script that uses the AD module for some operations.

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
}

When I try to run it on PowerShell ISE, I get the following exception:

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".

I tried running it without the Import-Module cmdlt, but it didn't recognize the Get-ADUser command. If you could shed some light on this, I'd really appreciate it!

Upvotes: 0

Views: 2909

Answers (1)

Travis Runyard
Travis Runyard

Reputation: 185

You might have two different copies of the ActiveDirectory module installed. Try checking your installed modules list:

Get-Module -list

If there is a conflict you should unload the module:

Remove-Module ActiveDirectory

Upvotes: 1

Related Questions