Powershell Remote Basics
Powershell Remote Basics
Powershell Remote Basics
0 remoting
Ravikanth Chaganti
Acknowledgments
Thanks to everyone who read my blog posts on PS remoting and provided feedback. Your
encouragement and support helped me write quite a bit about remoting and now this e-book.
Disclaimer
The content of this guide is provided as-is with no warranties. You are allowed to use the material
published in this guide any way you want as long as you credit the author. For any questions, you can
contact Ravikanth@ravichaganti.com . All trademarks acknowledged.
2
PART1 _______________________________________________________________________________________ 6
CHAPTER 1: INTRODUCTION TO REMOTING ________________________________________________________ 6
TRADITIONAL REMOTING IN POWERSHELL ______________________________________________________________ 6
OVERVIEW OF POWERSHELL 2.0 REMOTING ____________________________________________________________ 7
PowerShell 2.0 remoting requirements _________________________________________________________ 7
OVERVIEW OF REMOTING CMDLETS __________________________________________________________________ 8
Enable-PSRemoting ________________________________________________________________________ 8
Disable-PSRemoting ________________________________________________________________________ 8
Invoke-Command __________________________________________________________________________ 8
New-PSSession ____________________________________________________________________________ 9
Enter-PSSession ___________________________________________________________________________ 9
Exit-PSSession _____________________________________________________________________________ 9
Get-PSSession _____________________________________________________________________________ 9
Remove-PSSession _________________________________________________________________________ 9
Import-PSSession __________________________________________________________________________ 9
Export-PSSession __________________________________________________________________________ 9
Register-PSSessionConfiguration _____________________________________________________________ 10
Unregister-PSSessionConfiguration ___________________________________________________________ 10
Disable-PSSessionConfiguration _____________________________________________________________ 10
Enable-PSSessionConfiguration ______________________________________________________________ 10
Get-PSSessionConfiguration_________________________________________________________________ 10
Set-PSSessionConfiguration _________________________________________________________________ 10
Test-WSMan _____________________________________________________________________________ 10
Enable-WSManCredSSP ____________________________________________________________________ 10
Disable-WSManCredSSP____________________________________________________________________ 11
CHAPTER 2: ENABLE/DISABLE POWERSHELL REMOTING _____________________________________________ 12
TEST POWERSHELL REMOTING _____________________________________________________________________ 13
REMOTING IN WORKGROUP ENVIRONMENTS ___________________________________________________________ 14
On Windows XP __________________________________________________________________________ 14
Modify WSMan trusted hosts setting _________________________________________________________ 14
REMOTING IN MIXED DOMAIN ENVIRONMENT___________________________________________________________ 15
REMOTING IN AN ENTERPRISE _____________________________________________________________________ 15
DISABLE REMOTING ____________________________________________________________________________ 15
SUMMARY __________________________________________________________________________________ 16
CHAPTER 3: EXECUTE REMOTE COMMANDS _______________________________________________________ 17
RUN SCRIPT BLOCKS ON LOCAL OR REMOTE COMPUTER ____________________________________________________ 17
PASSING VARIABLES TO REMOTE SESSION ______________________________________________________________ 17
USING PERSISTENT SESSIONS WITH INVOKE-COMMAND ____________________________________________________ 18
RUNNING REMOTE COMMAND AS A BACKGROUND JOB_____________________________________________________ 18
SPECIFYING CREDENTIALS REQUIRED FOR REMOTING ______________________________________________________ 19
SUMMARY __________________________________________________________________________________ 19
CHAPTER 4: INTERACTIVE REMOTING SESSIONS ____________________________________________________ 20
Part1
Chapter 1: Introduction to remoting
Traditional remoting in PowerShell
A few cmdlets in PowerShell support accessing information on a remote system. These cmdlets have a
ComputerName parameter. For example the following cmdlets support the computername parameter
and hence can be used to access information from a remote computer.
Get-WmiObject
Invoke-WmiMethod
Limit-EventLog
Set-Service
Set-WmiInstance
Show-EventLog
Stop-Computer
Clear-EventLog
Get-Counter
New-EventLog
Register-WmiEvent
Remove-EventLog
Remove-WmiObject
Restart-Computer
Get-EventLog
Get-HotFix
Get-Process
Get-Service
Get-WinEvent
The remoting capability of these cmdlets is independent of PowerShell. It is up to the cmdlet author to
implement the remote access using methods such as remote procedure call (RPC), etc. This method of
remoting can be called traditional remoting or classic remoting.
One obvious disadvantage is that not all PowerShell cmdlets implement this type of remoting. So, for
example, if you want to execute Get-PSDrive or Get-ChildItem remotely on a different computer, it is not
possible. This is where the new PowerShell 2.0 remoting feature plays an important role. So, throughout
this guide, whenever we refer to remoting, we refer to the new remoting technology but not traditional
or classic remoting methods.
WinRM: http://msdn.microsoft.com/en-us/library/aa384426(VS.85).aspx
WS-Management: http://msdn.microsoft.com/en-us/library/aa384470(VS.85).aspx
3
UCEM as explained by Jeffery Snover: Universal Code Execution Model
4
MobileShell
2
on multiple computers. This cmdlet in its default form opens a session for running a command
against a remote computer and closes it once the execution is complete. This method may be slow and
can be worked around by specifying pre-defined session information.
New-PSSession
Invoke-Command cmdlet supports specifying an existing session to enhance the speed of overall
command execution. By specifying an existing session, we eliminate the need for creating/destroying
the sessions on the fly. New-PSSession cmdlet can be used to create a persistent connection to a remote
computer. By creating a persistent session, we will be able to share data, such as a function or the value
of a variable between different commands executing within the PSSession.
Enter-PSSession
Enter-PSSession cmdlet starts an interactive session with a single remote computer. During the session,
the commands that you type run on the remote computer, just as though you were typing directly on
the remote computer. You can have only one interactive session at a time. You can specify the PSSession
you created using New-PSSession as a parameter to this cmdlet.
Exit-PSSession
Exit-PSSession exits an interactive PS Session created using Enter-PSSession cmdlet.
Get-PSSession
The Get-PSSession cmdlet gets the Windows PowerShell sessions (PSSessions) that were created in the
current session. This cmdlet gets all the PSSessions returns all the PSSessions in to a variable when no
parameters are specified. You can then use the session information with other cmdlets such as InvokeCommand, Enter-PSSession, Remove-PSSession, etc.
Remove-PSSession
The Remove-PSSession cmdlet closes PS session(s). It stops any commands that are running in the
PSSessions, ends the PSSession, and releases the resources that the PSSession was using. If the
PSSession is connected to a remote computer, Remove-PSSession also closes the connection between
the local and remote computers.
Import-PSSession
Import-PSSession cmdlet uses the implicit remoting feature of PowerShell 2.0. Implicit remoting enables
you to import commands from a local/remote computer in to an existing PS session and run those
commands as if they were local to the session.
Export-PSSession
The Export-PSSession cmdlet gets cmdlets, functions, aliases, and other command types from another
PSSession on a local or remote computer and saves them to local disk as a Windows PowerShell module.
We can now use the Import-Module cmdlet to add the commands from the saved module to a PS
Session.
9
Register-PSSessionConfiguration
Any PS session created using Invoke-Command or New-PSSession or any other PowerShell remoting
cmdlet for that matter uses the default PS Session configuration as specified in the
$PSSessionConfigurationName variable. PS Session configuration determines which commands are
available in the session, and it can include settings that protect the computer, such as those that limit
the amount of data that the session can receive remotely in a single object or command. So, you can use
the Register-PSSessionConfiguration cmdlet creates and registers a new session configuration on the
local computer.
Unregister-PSSessionConfiguration
The Unregister-PSSessionConfiguration cmdlet deletes registered session configurations from the
computer. It is possible to delete the default PSSession configurations (Microsoft.PowerShell or
Microsoft.PowerShell32) using this cmdlet. In such a case, you can use Enable-PSRemoting cmdlet to recreate and register the default PS Session configurations.
Disable-PSSessionConfiguration
Disable-PSSessionConfiguration disables a registered PS Session configuration. Remember, this only
disables the configuration but not un-register or delete the information from local computer. These
disabled session configurations cannot be used to establish a remoting session.
Enable-PSSessionConfiguration
The Enable-PSSessionConfiguration cmdlet re-enables registered session configurations that have been
disabled by using the Disable-PSSessionConfiguration cmdlet.
Get-PSSessionConfiguration
The Get-PSSessionConfiguration cmdlet gets the session configurations that have been registered on the
local computer.
Set-PSSessionConfiguration
The Set-PSSessionConfiguration cmdlet changes the properties of the registered session configurations
on the local computer.
Test-WSMan
PowerShell remoting requires WinRM service to be running on the remote machines. You can use TestWSMan cmdlet to quickly check if you can establish a remoting session with other computers. If WinRM
is not enabled on remote machine, you can safely assume that PowerShell remoting is not enabled.
However, you cannot assume that PowerShell remoting is enabled just by verifying that WinRM service
is running. Remember, this cmdlet checks only for WinRM service and remoting requires many other
components to function.
Enable-WSManCredSSP
PowerShell remoting supports CredSSP authentication and the same can be enabled by using EnableWSManCredSSP cmdlet. The Enable-WSManCredSSP cmdlet enables CredSSP authentication on a client
or on a server computer. When CredSSP authentication is used, the users credentials are passed to a
10
remote computer to be authenticated. This type of authentication is designed for commands that create
a remote session from within another remote session. For example, you use this type of authentication
if you want to run a background job on a remote computer.
Disable-WSManCredSSP
The Disable-WSManCredSPP cmdlet disables CredSSP authentication on a client or on a server computer.
There are other WSMan cmdlets introduced in PowerShell 2.0 such as Connect-WSMan, DisconnectWSMan,
Get-WSManInstance,
New-WSManInstance,
New-WSManSessionOption,
RemoveWSManInstance and Set-WSManInstance. These cmdlets are not really meant for PowerShell remoting
but we will discuss them as required.
11
12
You should always use the more comprehensive Enable-PSRemoting cmdlet. You can use -force
parameter along with this cmdlet to silently enable remoting.
Trivia
PowerShell remoting cannot be enabled remotely
Note
A PowerShell session (PS Session) is an environment to run the remote commands and scripts.
PowerShell 2.0 provides various cmdlets to manage these sessions. To see a list of all PSSession cmdlets,
use Get-Command noun PSSession.
There is also a New-PSSessionOption cmdlet to change default behavior of a PS session. New-PSSession
and Enter-PSSession cmdlets have a parameter, -sessionOption, to specify custom session options. You
can use this to specify options such as
IdleTimeOut
Determines how long the PSSession stays open if the remote computer does not receive any
communication from the local computer, including the heartbeat signal. When the interval expires, the
PSSession closes.
OpenTimeOut
Determines how long the client computer waits for the session connection to be established. When the
interval expires, the command to establish the connection fails.
OperationTimeOut
Determines the maximum time that any operation in the PSSession can run. When the interval expires,
the operation fails.
SkipCACheck
Specifies that when connecting over HTTPS, the client does not validate that the server certificate is
signed by a trusted certification authority (CA).
SkipCNCheck
Specifies that the certificate common name (CN) of the server does not need to match the hostname of
13
the server. This option is used only in remote operations that use the HTTPS protocol.
SkipRevocationCheck
Does not validate the revocation status of the server certificate.
Remoting in an enterprise
To enable remoting on multiple computers in an enterprise or domain environment, you can use group
policy. For more information on this, refer to the HOW TO ENABLE REMOTING IN AN ENTERPRISE
section at http://technet.microsoft.com/en-us/library/dd347642.aspx
Disable remoting
You can use Disable-PSRemoting to disable remoting on the local computer. Disable-PSRemoting will
only disable the session configurations. This will *not* remove all the changes done by EnablePSRemoting. This includes leaving the WinRM service in enabled state and leaving all the listeners
created to enable PS remoting. You will have to manually undo these changes if they are not required by
any other component or service on the local computer.
If no other service or components on the local computer need WinRM service, you can disable WinRM
service by running
Set-Service winrm -StartupType Manual
Stop-Service winrm
To remove all WinRM listeners listening on default PS remoting port (5985)
Get-ChildItem WSMan:\localhost\Listener Recurse | Foreach-Object { $_.PSPath } | Where-Object { (Get-Item
"$_\Port").Value -eq 5985 } | Remove-Item
15
Summary
In this chapter, we looked at how to enable remoting for basic usage. We also looked at how to
configure computers in a workgroup and mixed domain environment to participate in PowerShell
remoting. Beware that disabling remoting wont undo changes done by Enable-PSRemoting. If remoting
is not required on the local computer, you should manually undo all the changes. This is a good security
practice. There are few more things you should be aware of while configuring a computer for remoting.
We will look at each of these in detail in part 2.
16
The above example may be a simple one but it shows how to use -ArgumentList parameter to pass local
variables to the remote session.
17
Once you run this, you will see the job details listed as shown here
18
When you use asJob parameter with Invoke-Command cmdlet, the background job gets created locally
but runs on the remote computer. Since this job is created locally, we can use *-Job cmdlets to manage
the job object.
For example, you can use Get-Job to monitor the status of the job and once the job status changes to
completed, you can use Receive-Job cmdlet to see the output of the script block specified.
Get-Job -Id 3 | Receive-Job
You can also use Start-Job within the script block to create a background job on the remote computer.
However, this way the job output will be available only on the remote computer. So, when you need to
get the output from this background job, you need to use Receive-Job within the script block to InvokeCommand.
For a complete discussion on background jobs in remoting, refer to About_Remote_Jobs article on
technet.
Summary
In this chapter, we looked at how Invoke-Command cmdlet can be used to execute commands on a
remote computer. We looked how to create a persistent session and use that along with InvokeCommand. You can use background jobs in remoting to execute time consuming commands as a job on
the remote machine. There are other parameters to Invoke-Command include session options, etc. We
will look at this in detail in part 2 of this guide.
19
You can now add the SharePoint snap-in using Add-PSSnapin cmdlet.
20
Add-PSSnapin Microsoft.SharePoint.PowerShell
Once the snap-in is loaded, you will have access to all the SharePoint 2010 cmdlets as if they are
available on the local computer. You can verify that by using Get-Help against one of the SharePoint
2010 cmdlets.
Get-Help Get-SPWeb Full
21
Figure 6 Get-PSSession
There are four ways to enter an existing PS Session for interactive remoting. I have highlighted the
available options in the above screenshot. You can use whichever way is convenient to you.
Method 1: Using session Id
Enter-PSSession -id 1
Summary
This chapter gave a quick overview of interactive remoting in PowerShell 2.0 and how to use EnterPSSession, Exit-PSSession and Get-PSSession cmdlets.
22
23
By default, Import-PSSession imports all commands except for commands that have the same names as
commands in the current session. To import all the commands, use the -AllowClobber parameter. You
will see a progress bar on top of the console window showing the progress of the import.
If you import a command with the same name as a command in the current session, the imported
command hides or replaces the original commands. This is because import session converts the cmdlets
to functions before importing and functions take precedence over cmdlets. So, imported commands
take precedence over the local commands with same name -- irrespective of the fact whether those
commands are loaded after importing a session or before.
To know more about the command precedence, read about_Command_Precedence.
However, aliases are an exception. Original aliases in the local session take precedence over imported
aliases.
24
In the above example we first create a PS session, import active directory module using InvokeCommand and then import the session in to the local session. This makes all the active directory cmdlets
available in the local session.
Now, we can connect do a different remote session and import cmdlets from that session also.
$s = New-PSSession -ComputerName SP2010-WFE
Invoke-Command -Session $s -ScriptBlock {Add-PSSnapin Microsoft.SharePoint.PowerShell}
Import-PSSession -Session $s
Now, within the local session, we have access to AD cmdlets from one computer and SharePoint 2010
cmdlets from another machine. This makes it easy to manage both from the same computer and local
session without worrying much about creating / destroying sessions.
Summary
Implicit remoting is about bringing remote commands to local session. This technique can be used to
import modules/snap-ins for commands that arent available natively to PowerShell. In this chapter, we
looked at how to create implicit remoting sessions and a few parameters used along with ImportPSSession cmdlet.
25
In the above example, the first two lines should be quite familiar by now. The third line is where the
magic happens. We tell Export-PSSession cmdlet to export all the commands, aliases, functions, etc
available in PS Session $s to a module on hard disk and name it ADRemoteCommands.
If the Export-PSSession is successful, you will see output similar to what is shown here
In the above output, it is clear that Export-PSSession generates .psm1, .psd1 and format data file for the
module automatically. Now, you can load the module at any later point in time to get access to the
remote commands.
This imports all remote commands available in the module to local session. Whenever we execute a
remote command, implicit remoting kicks in, establishes the remote session, executes the command in
remote session and returns the output. All this is done without you really using any remoting related
cmdlets. If establishing a remote session requires a password, you will be prompted for one.
Limitations of Export-PSSession
Using Export-PSSession has the same limitations as implicit remoting. You cannot use Export-PSSession
to export a Windows PowerShell provider. You cannot start a program with user interface or requires
access to interactive desktop. The exported module does not include the session options used to create
the session. So, if you need any specific session options to be configured before running remote
commands, you need to create a PS Session with all the required session options before importing the
on disk module.
Summary
Saving a remote session to disk can be done using Export-PSSession cmdlet. This is a very quick method
to execute commands on a remote computer without explicitly creating a PS session or entering an
interactive remoting session.
This also brings us to the end of part 1. In part 1, we looked at the basics of PowerShell remoting such as
what is remoting, enabling remoting in various scenarios, executing remote commands and
importing/exporting remoting sessions. Part 2 of this guide looks at a bit more advanced aspects of
PowerShell remoting.
Keep reading..!
27
PART 2
Chapter 7: Understanding session configurations
In chapter 2, we saw that whenever PowerShell remoting is enabled, the default session configurations
get registered. Also, Invoke-Command, Enter-PSSession and New-PSSession cmdlets have a
ConfigurationName parameter which can be used to specify a different session configuration than the
default one. So, what are these session configurations?
So, in this part, we will look at all the PS session configuration cmdlets; discuss how to create custom PS
Session configurations and the need for it. Let us dive in to this now.
When you enable PowerShell remoting using Enable-PSRemoting, you will see a final step performing
Microsoft.PowerShell and Microsoft.PowerShell32 (on x64 systems) session configuration registrations.
These default session configurations are used when the remote users connecting to local system do not
specify a configuration name. By default, only members of administrators group have access to these
two session configurations. Hence, only members of administrators group will be able to create
remoting sessions by default.
Based on the above description, PowerShell session configurations can be used to
customize the remoting experience for users
delegate administration by creating session configuration with varying levels of access to system
In this chapter, we will look at session configurations and see how we can create custom session
configurations. We will discuss delegated administration at depth in a later chapter.
28
Figure 8 Get-PSSessionConfiguration
As you see in the above output, Get-PSSessionConfiguration lists all available session configurations on
the local computer and who has permission to access the configuration. No permissions have been
assigned yet to the new active directory configuration.
From a remote computer
Get-PSSessionConfiguration cmdlet cannot be used to access a list of PS Session configurations from a
remote computer. However, we can use Get-WSManInstance cmdlet to achieve this.
Get-WSManInstance winrm/config/plugin -Enumerate -ComputerName SP2010-WFE | Where `
{ $_.FileName -like '*pwrshplugin.dll'} | Select Name
This will list all the session configuration names as available on the remote computer. You can then use
one of the session configurations to connect to the remote computer using PowerShell remoting.
29
Note
You must be an administrator and run the above command at an elevated prompt. Also,
You must have access to the session configuration on the remote computer to be able to use it within
PowerShell remoting.
Select Allow -> (Execute) Invoke permission and click OK. You will be prompted to restart the WinRM
service. Now, an administrator or a member of administrators group will be able to use this session
configuration. Similarly, you can add a non-administrator user to the list of users/groups and then assign
appropriate permissions. This way, you can have non-administrator uses to remote in to the local
computer using PowerShell remoting. You can read more on this in the next chapter.
Summary
In this chapter, we looked at the basics of PowerShell session configurations and how to create custom
configurations. We also looked at cmdlets to manage these session configurations. By default, it is
necessary that you need to a part of local administrators group to remote in to computer. However,
using custom session configuration and permissions assigned to these configurations, we can enable a
non-administrator user to remote in to a computer using PowerShell remoting.
31
32
As you see above, get-Command lists only the commands we have in the Required Commands list.
However, if you have a large list of required commands, the method you have seen in the above code is
not scalable. Instead, you can use a denied list of commands that is relatively small. For example, if you
dont want your users to execute Stop-Process or Restart-Computer, your code will look like
$DeniedCommands = @("Stop-Process",
"Restart-Computer"
)
$ExecutionContext.SessionState.Applications.Clear()
$ExecutionContext.SessionState.Scripts.Clear()
Get-Command -CommandType Cmdlet, alias, function | ?{$DeniedCommands -contains $_.Name}
| %{$_.Visibility="Private"}
$ExecutionContext.SessionState.LanguageMode="RestrictedLanguage"
So, if you use this code for your startup script, you will see something like this
http://blogs.msdn.com/powershell/archive/2009/01/04/extending-and-or-modifing-commands-withproxies.aspx
What I have shown here is just one way of achieving control in the remote sessions. However, based on
your organization needs there could be a better way of doing this. These methods include user role
based restrictions, etc as discussed at a PDC09 session. Do refer to that for more information.
34
You can see an additional column in the output that shows the remote computer name with
PSComputerName as the column name. This wont be displayed if you run the same cmdlet on local
computer. So, if you dont want to display this information in the remote output you can use the HideComputerName parameter.
It is also possible that some cmdlets may not display PSComputerName property. For example, Get-Date.
In such a scenario you can add PSComputerName to the output of Get-Date as shown here
Invoke-Command -ComputerName Server01,Server02 -ScriptBlock {Get-Date} | ft DateTime,
PSComputerName Auto
35
36
Here, you can see a list of methods you can use against a process object. Now, let us take a look at how
this looks when we execute the same command in a remote session.
If you observe in the above screenshot, TypeName represents a deserialized object and there are no
methods that you can use against a process object. A deserialized object represents a snapshot of getprocess at the time of command execution in the remote session. This also means that you cant
execute methods such as Kill() against a deserialized process object. Also, no methods to modify the
property set will work in the local session.
Windows PowerShell blog has a nice post on how objects are to and from a remote session. I
recommend that you read this post for more information.
Now, if we try to run the same in a remote session using Invoke-Command, you will see
37
As you see in the above screenshot, the output from a remote session is quite different from the one
you saw in a local session. This is because we dont have the formatting data available on the Windows 7
computer.
We can use Get-FormatData, Export-FormatData and Update-FormatData cmdlets to get the formatting
data from a remote computer to local session. To do this
$s = New-PSSession -ComputerName SP2010-WFE
Invoke-Command -session $s -ScriptBlock {Add-PSSnapin Microsoft.SharePoint.PowerShell}
Invoke-Command -Session $s -ScriptBlock {Get-FormatData -TypeName *SharePoint*} | Export-FormatData Path C:\scripts\SharePoint.Format.ps1xml
Update-FormatData -PrependPath C:\scripts\SharePoint.Format.ps1xml
The above code snippet will let you import the formatting data for all SharePoint cmdlets in to the local
session. Now, if we run Get-SPSite in the remote session using Invoke-Command,
Now, with the formatting information in the local session, you can see that Get-SPSite output is
formatted similar to the one we saw when we ran the cmdlet in a local session. However, make a note
that this applies only to the current session. If you close and re-open the PowerShell console, the
formatting data will be lost. You can add the Update-FormatData cmdlet to your PowerShell profile to
make the format data across all PowerShell sessions.
38
Now, within the remoting session to computer B, we want to execute a command as below to
create test.txt on computer C.
Invoke-Command -ComputerName Test-PC.SP2010lab.com -credential SP2010LAB\Administrator ScriptBlock {[System.IO.File]::Create(\\FileServer\Share\Test.txt)}
This command results in an Access Denied error as shown above. This command fails since the remote
session tries to access the file share using the machine credentials instead of the credentials used to
invoke the remote session. We could have successfully created the text file if there was a way to pass or
6
7
CredSSP
multi-hop authentication
39
delegate credentials from the client so that we can authenticate to the file share. This is what is called
multi-hop authentication and PowerShell remoting enables this using CredSSP.
Delegating credentials
The cmdlets to create a remoting session Invoke-Command, Enter-PSSession and New-PSSession
have a parameter to specify the authentication method as CredSSP. However, before we use this
parameter, we need to enable credSSP on the computers participating in multi-hop authentication. Also,
when enabling CredSSP, we need to specify the role client or server of a computer. A client is the
computer from which the remoting session is initiated and server is the computer from which the multihop authentication is triggered. So, from the above example, we need to enable CredSSP authentication
on computer A and computer B.
PowerShell 2.0 provides the following cmdlets to manage CredSSP authentication.
1. Enable-WSManCredSSP
2. Disable-WSManCredSSP
3. Get-WSManCredSSP
Let us now look at how we enable WSManCredSSP and specify client / server roles. First, let us enable
CredSSP on computer A.
Note
You need to run these cmdlets in an elevated prompt.
Enable-WSManCredSSP -Role Client -DelegateComputer "*.SP2010lab.com"
As shown here, you can use Enable-WSManCredSSP cmdlet to enable CredSSP authentication and
specify the computer role as client. When the computer role is defined as a client, you can also specify
the DelegateComputer parameter to specify the server or servers that receive the delegated credentials
from the client. The delegateComputer accepts wildcards as shown above. You can also specify * to
specify all computers in the network.
When Enable-WSManCredSSP cmdlet is used to enable CredSSP on the client by specifying client in the role
parameter. The cmdlet then performs the following:
1. The WS-Management setting <localhost|computername>\Client\Auth\CredSSP is set to true.
2. Sets the Windows CredSSP policy AllowFreshCredentials to WSMan/Delegate on the client.
Now, we will enable CredSSP on computer B and deginate that as server.
40
As you see here, we see the output from Create() method which shows the details of the newly created
file.
Caution
CredSSP authentication delegates the users credentials from the local computer to a remote computer.
This practice increases the security risk of the remote operation. If the remote computer is
compromised when credentials are passed to it the credentials can be used to control the network
session.
You can use Disable-WSManCredSSP to disable CredSSP authentication on a client or a server computer.
Disable-WSManCredSSP -Role Client
Disable-WSManCredSSP -Role Server
You can use Get-WSManCredSSP cmdlet to verify if a computer has CredSSP enabled and also the role
(client/server).
Summary
Credential delegation is required when you need to access or authenticate to a second computer within
a remote session. Some of the other examples also include SharePoint 2010 cmdlets. Since, every
SharePoint cmdlet will have to gather data from various servers within the farm and depending on how
you farm accounts are configured, you may need to use CredSSP authentication to authenticate to all
the servers within the farm.
This chapter concludes this remoting guide.
41
42