Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How do I import a module for script use?

$
0
0

I have a script that uses the AD module for some operations. Here is the code:

#04/24/2014
#UsAer Logger
#Author: Alexander Bazzi
#Property of AerSale, Inc

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!

Many thanks in advance.

Best,

Alex



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>