Last week, we discussed the new Active Directory Domain Services-related PowerShell Cmdlets in Windows Server 2012 R2.
In the requirements I mentioned that you needed at least one system with the Windows Server 2012 R2 or Windows 8.1 version of the Active Directory Module for Windows PowerShell feature installed.
However, as Aleksandar Nikolic (PowerShell MVP) pointed out to me, purely having one Windows Server 2012 R2-based Domain Controller with this feature allows other systems, including down-level systems as far back as Windows XP and systems without the Active Directory Module for Windows PowerShell to use these new Active Directory Domain Services-related PowerShell Cmdlets.
Of course, you could argue that you could always use these Cmdlets through Remote Desktop and PowerShell Remoting, but PowerShell has two distinct features up its sleeve, depending on your version of PowerShell:
PowerShell 2.0
On systems with PowerShell 2.0, you can use the Import-PSSession Cmdlet, pointed towards a Windows Server 2012 R2-based Domain Controller (or Windows 8.1-based domain-joined device with the Active Directory Module for Windows PowerShell feature installed):
$dc=New-PSSession -ComputerName DC1
Import-PSSession -Session $dc -AllowClobber
Import-Module ActiveDirectory
PowerShell 2.0 is available by default on Windows 7. You can download the Windows Management Framework, which includes Windows PowerShell 2.0, WinRM 2.0, and BITS 4.0 for Windows XP with ServicePack 3 and Windows Vista with ServicePack 1.
PowerShell 3.0 (and up)
On systems with at least PowerShell 3.0, you can use the PowerShell 2.0 method above, but you can also use the Import-Module Cmdlet with the -PSSession parameter:
$dc=New-PSSession -ComputerName DC1
Import-Module -PSSession $dc -Name ActiveDirectory
Note:
You will need to allow scripts, before you can successfully run the above. Type Set-ExecutionPolicy unrestricted to this purpose, before running the above two lines of PowerShell code.
PowerShell 3.0 is available by default on Windows 8. After you download and install .Net Framework 4 or .Net Framework 4.5, you can download and install the Windows Management Framework 3.0, which includes PowerShell 3.0 and WMI 3.0 on Windows 7 with ServicePack 1.
Concluding
Take advantage of all the available Active Directory Domain Services-related PowerShell Cmdlets using the Import-PSSession and/or the Import-Module Cmdlet with the
-PSSession parameter on down-level systems.
Indeed, a neat trick!
Related blogposts
New features in AD DS in Windows Server 2012 R2, Part 4: PowerShell Cmdlets
New features in AD DS in Windows Server 2012, Part 4: New PowerShell Cmdlets
Active Directory Services and PowerShell manageability
KnowledgeBase: Incorrect results when you run AD Windows PowerShell Cmdlets on a Windows Server 2012 or Windows Server 2008 R2-based Domain Controller
Further reading
Import-PSSession (PowerShell 4.0)
Powershell Remoting: using imported module cmdlets in a remote pssession
Import and Export PSSession
Get Full Control over your Exchange remote PowerShell session
Deep Dive video: Constrained PowerShell Endpoints – Aleksandar Nikolic
Hat Tip
Thanks to Aleksandar Nikolic for the tip!
Login