【问题标题】:Installing the Active Directory PowerShell Module on Windows 10在 Windows 10 上安装 Active Directory PowerShell 模块
【发布时间】:2022-02-24 01:44:18
【问题描述】:

我正在尝试通过technet提供的这组命令在windows 10上安装powershell的活动目录模块,但我仍然无法成功,我尝试了很多次并且以管理员身份运行powershell但是问题仍然存在,看起来它卡在循环打印中:“。” 我从link 下载了代码(它在一个 .txt 文件中)

我还附上了代码本身和执行代码后的结果截图。

基本上,提供的代码会创建一个名为 Install-ADModule 的函数,然后调用它:

#requires -RunAsAdministrator

<#-----------------------------------------------------------------------------
Ashley McGlone, Microsoft Premier Field Engineer
http://aka.ms/goateepfe
February 2016
Install-ADModule
For Windows 10 performs the following tasks:
- Downloads and installs Windows 10 RSAT for the appropriate system architecture
- Enables the RSAT AD PowerShell feature
- Updates help for the AD module
- Displays validation output
-------------------------------------------------------------------------------
LEGAL DISCLAIMER
This Sample Code is provided for the purpose of illustration only and is not
intended to be used in a production environment.  THIS SAMPLE CODE AND ANY
RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.  We grant You a
nonexclusive, royalty-free right to use and modify the Sample Code and to
reproduce and distribute the object code form of the Sample Code, provided
that You agree: (i) to not use Our name, logo, or trademarks to market Your
software product in which the Sample Code is embedded; (ii) to include a valid
copyright notice on Your software product in which the Sample Code is embedded;
and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and
against any claims or lawsuits, including attorneys’ fees, that arise or result
from the use or distribution of the Sample Code.

This posting is provided "AS IS" with no warranties, and confers no rights. Use
of included script samples are subject to the terms specified
at http://www.microsoft.com/info/cpyright.htm.
-----------------------------------------------------------------------------#>


<#
.SYNOPSIS
Installs the AD PowerShell module from RSAT for Windows 10
.DESCRIPTION
Performs the following tasks:
- Downloads and installs Windows 10 RSAT for the appropriate system architecture
- Enables the RSAT AD PowerShell feature
- Updates help for the AD module
- Displays validation output
.NOTES
Requires an elevated PowerShell host.

Requires an internet connection to download the RSAT install.

The RSAT hotfix download (<100MB) will be stored in the Downloads
folder of the user running the script.

Checks the following before taking action:
- Is the system running Windows 10?
- Is the RSAT already installed?
- Is the AD PowerShell feature already enabled?
.PARAMETER Test
Switch parameter to validate the install. Performs the following:
- Displays the RSAT update file that was downloaded.
- Confirms the hotfix is installed.
- Displays help for Get-ADDomain.
- Run the cmdlets Get-ADDomain.
.EXAMPLE
Install-ADModule -Verbose
.EXAMPLE
Install-ADModule -Test -Verbose
#>
Function Install-ADModule {
    [CmdletBinding()]
    Param(
        [switch]$Test = $false
    )

    If ((Get-CimInstance Win32_OperatingSystem).Caption -like "*Windows 10*") {
        Write-Verbose '---This system is running Windows 10'
    } Else {
        Write-Warning '---This system is not running Windows 10'
        break
    }

    If (Get-HotFix -Id KB2693643 -ErrorAction SilentlyContinue) {

        Write-Verbose '---RSAT for Windows 10 is already installed'

    } Else {

        Write-Verbose '---Downloading RSAT for Windows 10'

        If ((Get-CimInstance Win32_ComputerSystem).SystemType -like "x64*") {
            $dl = 'WindowsTH-KB2693643-x64.msu'
        } Else {
            $dl = 'WindowsTH-KB2693643-x86.msu'
        }
        Write-Verbose "---Hotfix file is $dl"

        Write-Verbose "---$(Get-Date)"
        #Download file sample
        #https://gallery.technet.microsoft.com/scriptcenter/files-from-websites-4a181ff3
        $BaseURL = 'https://download.microsoft.com/download/1/D/8/1D8B5022-5477-4B9A-8104-6A71FF9D98AB/'
        $URL = $BaseURL + $dl
        $Destination = Join-Path -Path $HOME -ChildPath "Downloads\$dl"
        $WebClient = New-Object System.Net.WebClient
        $WebClient.DownloadFile($URL,$Destination)
        $WebClient.Dispose()

        Write-Verbose '---Installing RSAT for Windows 10'
        Write-Verbose "---$(Get-Date)"
        # http://stackoverflow.com/questions/21112244/apply-service-packs-msu-file-update-using-powershell-scripts-on-local-server
        wusa.exe $Destination /quiet /norestart /log:$home\Documents\RSAT.log

        # wusa.exe returns immediately. Loop until install complete.
        do {
            Write-Host "." -NoNewline
            Start-Sleep -Seconds 3
        } until (Get-HotFix -Id KB2693643 -ErrorAction SilentlyContinue)
        Write-Host "."
        Write-Verbose "---$(Get-Date)"
    }

    # The latest versions of the RSAT automatically enable all RSAT features
    If ((Get-WindowsOptionalFeature -Online -FeatureName `
        RSATClient-Roles-AD-Powershell -ErrorAction SilentlyContinue).State `
        -eq 'Enabled') {

        Write-Verbose '---RSAT AD PowerShell already enabled'

    } Else {

        Write-Verbose '---Enabling RSAT AD PowerShell'
        Enable-WindowsOptionalFeature -Online -FeatureName RSATClient-Roles-AD-Powershell

    }

    Write-Verbose '---Downloading help for AD PowerShell'
    Update-Help -Module ActiveDirectory -Verbose -Force

    Write-Verbose '---ActiveDirectory PowerShell module install complete.'

    # Verify
    If ($Test) {
        Write-Verbose '---Validating AD PowerShell install'
        dir (Join-Path -Path $HOME -ChildPath Downloads\*msu)
        Get-HotFix -Id KB2693643
        Get-Help Get-ADDomain
        Get-ADDomain
    }
}


Get-Help Install-ADModule -Full

Install-ADModule -Verbose

#Install-ADModule -Test -Verbose

break

<#
# Remove
wusa.exe /uninstall /kb:2693643 /quiet /norestart /log:$home\RSAT.log
#>

执行创建的函数后的结果:

PS C:\WINDOWS\system32> Install-ADModule -Verbose
VERBOSE: Perform operation 'Enumerate CimInstances' with following parameters, ''className' = Win32_OperatingSystem,'namespaceName' = root\cimv2'.
VERBOSE: Operation 'Enumerate CimInstances' complete.
VERBOSE: ---This system is running Windows 10
VERBOSE: ---Downloading RSAT for Windows 10
VERBOSE: Perform operation 'Enumerate CimInstances' with following parameters, ''className' = Win32_ComputerSystem,'namespaceName' = root\cimv2'.
VERBOSE: Operation 'Enumerate CimInstances' complete.
VERBOSE: ---Hotfix file is WindowsTH-KB2693643-x64.msu
VERBOSE: ---07/02/2018 14:51:35
VERBOSE: ---Installing RSAT for Windows 10
VERBOSE: ---07/02/2018 14:51:57
......................... (Here is where it keeps printing dots)

截图:

注意: 我的windows版本是:Windows 10 Home 64-bit (10.0, Build 17134)

我希望你们能帮助我解决这个问题。 问候!

【问题讨论】:

  • 安装 RSAT 似乎只需要一段时间,这并非闻所未闻。你要等多久?这是正在运行的命令: wusa.exe $Destination /quiet /norestart /log:$home\Documents\RSAT.log 查看 RSAT.log 文件,看看那里是否有任何问题。但这可能只是安装缓慢。
  • @jbsmith 嗯,例如早上我停止了它,因为我花了大约 1 小时,而循环仍在运行,可以花超过 1 小时吗?哦,好的,谢谢! !嗯,我如何检查那个 .log 文件?
  • Windows 10 家庭版可能不支持 RSAT 窗口功能。几年前,我在尝试在 Windows 10 家庭版上使用 Hyper-V 管理器时遇到了这个问题,后来发现你不能在“家庭”版 Windows 中使用它。我肯定是错的,但只是一个想法
  • cet51 正确,win 10 home 无法安装rsat。
  • @cet51 非常感谢!我刚刚在另一台装有 windows 10 pro 的电脑上试了一下,结果成功了!

标签: powershell active-directory windows-10


【解决方案1】:

RSAT 在 Windows 的“家庭”版本上不可用。我在 windows 10 home 上遇到了 hyper-v 的类似问题,但在付费升级到 windows 10 pro 后它工作得很好。

【讨论】:

    【解决方案2】:

    我能够在 Windows 10 Pro 上安装适用于 Powershell 的 Active Directory 模块

    1. Settings->Apps->add a features: RSAT active directory domain services and lightweight directory services
    
    this is the feature on demand
    
    2. From powershell run as administrator: Import-Module -Name ActiveDirectory
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 2020-08-28
      相关资源
      最近更新 更多