簡體   English   中英

PowerShell導入模塊腳本異常

[英]PowerShell Import-Module script exception

我有一個使用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命令。 如果您能對此有所了解,我將不勝感激!

您可能安裝了ActiveDirectory模塊的兩個不同副本。 嘗試檢查已安裝的模塊列表:

Get-Module -list

如果存在沖突,則應卸載模塊:

Remove-Module ActiveDirectory

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM