Using PowerShell to Remote Server Administration in Windows

This article describes how to use Remote Server administration without installing the RSAT tools.

Get-ADUser -Identity lexh

0968099d1ba605acd9eb94afa60f9238

Let’s say for example the Active Directory PowerShell module is something that you use on a daily basis and it’s necessary to perform your daily tasks. Well, you’re out of luck because the RSAT tools are not installed by default on Windows 10. Before you consider using RDP or the GUI to perform your tasks, let’s take a look at a viable solution in PowerShell.

Create a PSSession to one of your domain controllers, specifying alternate credentials if necessary:

$session = New-PSSession -ComputerName horizon.local -Credential (Get-Credential)

0968099d1ba605acd9eb94afa60f9238

If the specified domain controller is running PowerShell version 2, you’ll need to import the Active Directory module, but if it’s running PowerShell version 3 or higher, you can skip this step:

Invoke-Command -Session $session {Import-Module -Name ActiveDirectory}

0968099d1ba605acd9eb94afa60f9238

Import the PSSession and specify the Active Directory module:

Import-PSSession -Session $session -Module ActiveDirectory

0968099d1ba605acd9eb94afa60f9238

What we done now is to use the implicit remoting to create shortcuts of the Active Directory cmdlets on the local computer from the domain controller that was previously specified. When the active directory cmdlets are executed, they run on the domain controller through the PSSession that was created but it will seem as if they exist locally.

The problem though is this has to be recreated each time PowerShell is restarted. Or does it? Wouldn’t it be awesome to be able to make these shortcuts to the Active Directory cmdlets persistent so they exist each time PowerShell is opened on your local computer?

All we really need to do accomplish this is to simply use the Export-PSSession cmdlet to save the module:

Export-PSSession -Session $session -Module ActiveDirectory -OutputModule "$env:ProgramFiles\WindowsPowerShell\Modules\ActiveDirectory" -FormatTypeName * -AllowClobber

0968099d1ba605acd9eb94afa60f9238

I’ve now closed my PowerShell console and reopened it. Now when I try to use one of the cmdlets that’s part of the Active Directory module, the PSSession is automatically recreated without having to jump through the hoops of setting up implicit remoting again:

Get-ADUser -Identity lexh

0968099d1ba605acd9eb94afa60f9238

Note: PowerShell remoting must be enabled on the domain controller that you’re attempting to use with implicit remoting as shown in this blog article, but if it’s running Windows Server 2012 or higher, PowerShell remoting is already enabled by default.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s