2013-07-09 70 views
50

我已經使用以下查詢來列出Windows 2008服務器中的用戶,但失敗並且得到以下錯誤。術語'Get-ADUser'不被識別爲cmdlet的名稱

$server='client-pc-1';$pwd= convertto-securestring 'password$' -asplaintext - 
force;$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist 'Administrator',$pwd; invoke-command -computername $server -credential 
$cred -scriptblock {Get-ADUser -Filter (enabled -ne $true)} 

下面給出的例外......任何人都可以幫助我解決這個問題嗎?

The term 'Get-ADUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct 
and try again. 
    + CategoryInfo   : ObjectNotFound: (Get-ADUser:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

回答

71

如果ActiveDirectory的模塊存在於您的代碼之前添加

import-module activedirectory 

要檢查是否存在嘗試:

get-module -listavailable 

的ActiveDirectory模塊默認目前在Windows Server 2008 R2,安裝了這種方式:

Import-Module ServerManager 
Add-WindowsFeature RSAT-AD-PowerShell 

對於有它的工作,你至少需要一個DC作爲Windows 2008 R2在域中安裝了Active Directory Web服務(ADWS)。

對於Windows Server 2008閱讀here如何安裝它

+0

@ShayLevy感謝編輯'[正則表達式]'\ s'';) –

+0

NP :)雖然我將其更改爲:獲得模塊的ActiveDirectory -listavailable –

+0

@ShayLevy是的,它是更好地檢查特定模塊!我的意圖是幫助用戶1805353知道哪個模塊可以加載。 –

26

檢查here如何在默認情況下添加的ActiveDirectory模塊,如果不存在。這可以在任何機器上完成,然後它將允許您訪問您的活動目錄「域控制」服務器。

編輯

爲了防止過期鏈接的問題(我發現MSDN博客消失在過去沒有理由),在Windows 7中,你需要下載並安裝Remote Server Administration Tools (KB958830)本質。在安裝執行以下步驟之後: - >程序和功能 -

  • 打開控制面板>打開/關閉Windows功能
  • 找到「遠程服務器管理工​​具」,然後展開它
  • 查找「角色管理工具「並將其展開
  • 找到」AD DS和AD LDS工具「並將其展開
  • 選中」Active Directory模塊對於Windows PowerShell「旁邊的複選框。
  • 單擊確定,並允許Windows安裝的功能

的Windows服務器版本應該已經是確定的,但如果沒有你需要下載並安裝Active Directory Management Gateway Service。如果這些鏈接中的任何一個都停止工作,您仍然應該能夠搜索知識庫文章或下載名稱並找到它們。

+0

@StevePettifer:如果你編輯答案 – Jay

+0

@jay公平點,會更好。認爲我很匆忙,這給了我我需要的答案,但是腦子裏已經死了。現在編輯答案並刪除評論。 –

3

如果您沒有看到Active Directory,那是因爲您沒有安裝AD LS用戶和計算機功能。轉到管理 - 添加角色&功能。在添加角色和功能嚮導中,在功能選項卡上,選擇遠程服務器管理工​​具,選擇 - 角色管理工具 - 選擇AD DS和DF LDS工具。

之後,您可以看到PS Active Directory軟件包。

-2
get-windowsfeature | where name -like RSAT-AD-PowerShell | Install-WindowsFeature 
相關問題