如何在PowerShell CLM模式下列舉域資訊?
本文我將快速簡要的向大家介紹我近來一直在使用和拿來教學的技術。通過該技術你可以在沒有獲取RSAT和管理許可權的情況下,使用Micorosft的Shell/">PowerShell ActiveDirectory模組。我是從 ofollow,noindex" target="_blank">這篇博文 中瞭解到這種技術的。
因此,如果你可以訪問已安裝模組的伺服器(如DC),請將Microsoft.ActiveDirectory.Management.dll從 C:\Windows\Microsoft.NET\assembly\GAC_64\Microsoft.ActiveDirectory.Management複製到你自己的機器上,然後使用Import-Module cmdlet匯入DLL:
PS C:\> Import-Module C:\ADModule\Microsoft.ActiveDirectory.Management.dll -Verbose
注意,如果你執行Get-Command -Module ActiveDirectory,將不會返回任何內容。想要獲取到,請從伺服器以下位置複製模組目錄:C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ActiveDirectory\。然後,使用Import-Module命令,先匯入DLL然後匯入模組:
PS C:\> Import-Module C:\ADModule\Microsoft.ActiveDirectory.Management.dll -Verbose PS C:\> Import-Module C:\AD\Tools\ADModule\ActiveDirectory\ActiveDirectory.psd1 PS C:\> Get-Command -Module ActiveDirectory
使用cmdlet有許多好處,例如較低的AV檢測率,覆蓋範圍廣(在我之後的文章中我還將用到cmdlet),強大的過濾器,以及由Microsoft簽名等。
我從Server 2016上傳了一個模組副本到Github上: https://github.com/samratashok/ADModule
該模組可以在PowerShell約束語言模式(CLM)中完美執行。