Computer >> Hướng Dẫn Máy Tính >  >> Hệ Thống >> Windows 10

Triển khai mô-đun PowerShell Active Directory không cài RSAT

Trong bài trước chúng ta chỉ cách dùng cmdlet Set-ADComputer trong script logon GPO lưu thông tin user đang đăng nhập vào thuộc tính đối tượng AD computer. Một bình luận viên đúng khi nhận xét để làm điều đó, phải cài RSAT với Active Directory for Windows PowerShell trên tất cả máy user – việc tốn thời gian. Tôi quyết định thử tìm hiểu có thể dùng cmdlet mô-đun PowerShell ActiveDirectory không cài RSAT trên máy user không. Và tôi làm được!

Giả sử, có server chạy Windows Server 2012 R2, đã cài RSAT và RSAT-AD-PowerShell module. Nhiệm vụ: copy file RSAT-AD-PowerShell sang workstation user và import để chạy các cmdlet AD module. Tôi cố dùng máy chạy Windows 10 LTSC (dựa trên build 1809) làm workstation để chứng minh phiên bản RSAT-AD-PowerShell cũ được hỗ trợ trên OS mới hơn.

Trước hết, copy tất cả file mô-đun AD từ Windows Server 2012 R2 sang Windows 10. Tạo thư mục C:\PS\ADPoSh và copy toàn bộ nội dung C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ActiveDirectory vào đó.

Sau đó copy các file sau từ thư mục C:\Windows\WinSxS:

  • Microsoft.ActiveDirectory.Management.dll
  • Microsoft.ActiveDirectory.Management.resources.dll

Bạn tìm thư viện này bằng tìm kiếm trong WinSxS. Trong ví dụ, đường dẫn đầy đủ trên Windows Server 2012 R2:

"C:\Windows\WinSxS\amd64_microsoft.activedirectory.management_31bf3856ad364e35_6.3.9600.16503_none_09aa35cd49da6068\Microsoft.ActiveDirectory.Management.dll"
"C:\Windows\WinSxS\amd64_microsoft.activedir..anagement.resources_31bf3856ad364e35_6.3.9600.16384_en-us_efefcf68718a71bc\Microsoft.ActiveDirectory.Management.resources.dll"

Sau đó copy thư mục C:\PS\ADPoSh (kích thước ~1.3MB) sang máy Windows 10 chưa cài RSAT AD module cho PowerShell.

Thử import mô-đun Active Directory copy vào phiên PowerShell hiện tại:

Import-Module "C:\PS\ADPoSh\Microsoft.ActiveDirectory.Management.dll"
Import-Module "C:\PS\ADPoSh\Microsoft.ActiveDirectory.Management.resources.dll"

Mô-đun import thành công, bạn có thể dùng bất kỳ cmdlet AD module để quản lý và lấy thông tin từ domain AD (ví dụ Get-ADUser, Get-ADComputer, Get-ADGroup, v.v.).

Nếu lỗi 'Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running' xảy ra, đảm bảo Active Directory Web Services (ADWS) trên domain controller gần nhất đang chạy và cổng TCP 9389 không bị tường lửa chặn.

Tìm DC có vai trò ADWS trong domain bằng lệnh:

Get-ADDomainController -Discover -Service “ADWS”

Kiểm tra khả năng truy cập dịch vụ ADWS dùng Test-NetConnection:

Test-NetConnection DC01 -port 9389

Để chạy cmdlet đối với domain controller cụ thể, dùng tham số –Server:

Get-ADUser jbrion –server dc01.woshub.com

Bạn có thể dùng cmdlet mô-đun AD PowerShell cho đến khi đóng phiên PowerShell. Có thể copy file mô-đun AD lên tất cả máy domain dùng GPO.