PowerShell提示輸入命令不是有效命令

來任務了,由於要Windows服務器版本要升級:2008 -> 2016,所以要做很多的準備工作,比如OU, GPO。由於OU劃分很細,有幾百個OU,要在2016OU下面新建所有在2008OU下已經存在的OU。那就用PowerShell來搞搞吧!但是找了一臺2008的server,運行一下Get-ADOrganizationalUnit這個PowerShell的命令,我去,竟然提示我不是有效的命令,錯誤詳細信息見下:
PowerShell提示輸入命令不是有效命令

奇怪了,之前在另外一臺server上面還是可以用的,剛開始懷疑是不是PowerShell版本太低了,索性查一下:

PS C:\Users\admin> $PSVersionTable

Name                           Value                                                                                                                                                         
----                           -----                                                                                                                                                         
PSVersion                      5.1.14393.2515                                                                                                                                                
PSEdition                      Desktop                                                                                                                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                       
BuildVersion                   10.0.14393.2515                                                                                                                                               
CLRVersion                     4.0.30319.42000                                                                                                                                               
WSManStackVersion              3.0                                                                                                                                                           
PSRemotingProtocolVersion      2.3                                                                                                                                                           
SerializationVersion           1.1.0.1   

版本都5.1了,不是很老啊!OK,那再來看看有沒有AD模塊吧,畢竟這個命令是對AD的操作。運行: get-module -listavailable 回車,走你,結果一看。原來如此,目測沒有AD模塊。

PowerShell提示輸入命令不是有效命令

那就導入一下吧,運行:

PS C:\Windows\system32> Add-WindowsFeature RSAT-AD-PowerShell
然後再運行一把get-module,看一下,ActiveDirectory加載過來了
PS C:\Windows\system32> get-module -listavailable

PowerShell提示輸入命令不是有效命令

最後運行一下命令:PS C:\Windows\system32> Get-ADOrganizationalUnit,不再報錯,而且提示需要參數,着就對了。
PowerShell提示輸入命令不是有效命令

我在另外一個server上面也試了另外一種方法:
首先運行:get-module -listavailable 查看ActiveDirectory模塊是否已經加載。
然後就是直接運行:import-module activedirectory
如果沒有報錯,就再運行:get-module -listavailable
這個時候ActiveDirectory模塊就被導入了,關於AD相關的PowerShell命令你就可以開始用了。

The term 'Get-ADOrganizationalUnit' 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.
At line:5 char:38
+ $SVSOUList = Get-ADOrganizationalUnit <<<<  -SearchBase $sourceOU -Filter {Name -like "W2K8_*"} |select -ExpandProperty Name
    + CategoryInfo          : ObjectNotFound: (Get-ADOrganizationalUnit:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 ________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
PS C:\Users\admin> import-module activedirectory

________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
PS C:\Users\admin> get-module -listavailable

ModuleType Name                      ExportedCommands                                                           
---------- ----                      ----------------                                                           
Manifest   ActiveDirectory           {}                                                                         
Manifest   ADRMS                     {}                                                                         
Manifest   AppLocker                 {}                                                                         
Manifest   BestPractices             {}                                                                         
Manifest   BitsTransfer              {}                                                                         
Manifest   GroupPolicy               {}                                                                         
Manifest   PSDiagnostics             {}                                                                         
Manifest   ServerManager             {}                                                                         
Manifest   TroubleshootingPack       {}                                                                         
Manifest   Citrix.XenDesktop.Admin   {}                                                                         
Manifest   Citrix.Common.Commands    {}                                                                         
Binary     TelemetryModule           {}                                                                         
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章