@@ -11,78 +11,75 @@ title: about_PSSessions
11
11
12
12
## Short description
13
13
14
- Describes Windows PowerShell sessions (PSSessions) and explains how to
15
- establish a persistent connection to a remote computer.
14
+ Describes PowerShell sessions (PSSessions) and explains how to establish a
15
+ persistent connection to a remote computer.
16
16
17
17
## Long description
18
18
19
- To run Windows PowerShell commands on a remote computer, you can use the
20
- ** ComputerName** parameter of a cmdlet, or you can create a Windows PowerShell
21
- session (PSSession) and run commands in the PSSession.
19
+ To run PowerShell commands on a remote computer, you can use the
20
+ ** ComputerName** parameter of a cmdlet, or you can create a PowerShell session
21
+ (PSSession) and run commands in the PSSession.
22
22
23
- When you create a PSSession, Windows PowerShell establishes a persistent
24
- connection to the remote computer. Use a PSSession to run a series of related
25
- commands on a remote computer. Commands that run in the same PSSession can
26
- share data, such as the values of variables, aliases, and functions.
23
+ When you create a PSSession, PowerShell establishes a persistent connection to
24
+ the remote computer. Use a PSSession to run a series of related commands on a
25
+ remote computer. Commands that run in the same PSSession can share data, such
26
+ as the values of variables, aliases, and functions.
27
27
28
28
You can also create a PSSession on the local computer and run commands in it.
29
- A local PSSession uses the Windows PowerShell remoting infrastructure to
30
- create and maintain the PSSession.
29
+ A local PSSession uses the PowerShell remoting infrastructure to create and
30
+ maintain the PSSession.
31
31
32
- Beginning in Windows PowerShell 3.0, PSSessions are independent of the
33
- sessions in which they are created. Active PSSessions are maintained on the
34
- remote computer (or the computer at the remote end or "server-side" of the
35
- connection). As a result, you can disconnect from the PSSession and reconnect
36
- to it at a later time from the same computer or from a different computer.
32
+ Beginning in Windows PowerShell 3.0, PSSessions on Windows are independent
33
+ of the sessions in which they are created. Active PSSessions are maintained
34
+ on the remote computer (or the computer at the remote end or "server-side"
35
+ of the connection). As a result, on Windows you can disconnect from a PSSession
36
+ on a remote Windows computer and reconnect to it at a later time from the
37
+ same computer or from a different Windows computer.
37
38
38
39
This topic explains how to create, use, get, and delete PSSessions. For more
39
- advanced information, see
40
- [ about_PSSession_Details] ( about_PSSession_Details.md ) .
40
+ advanced information, see [ about_PSSession_Details] [ 01 ] .
41
41
42
- Note: PSSessions use the Windows PowerShell remoting infrastructure. To use
43
- PSSessions, the local and remote computers must be configured for remoting.
44
- For more information, see
45
- [ about_Remote_Requirements] ( about_Remote_Requirements.md ) .
42
+ Note: PSSessions use the PowerShell remoting infrastructure. To use PSSessions,
43
+ the local and remote computers must be configured for remoting. For more
44
+ information, see [ about_Remote_Requirements] [ 02 ] .
46
45
47
46
In Windows Vista and later versions of Windows, to create a PSSession on a
48
- local computer, you must start Windows PowerShell with the "Run as
49
- administrator" option.
47
+ local computer, you must start PowerShell with the "Run as administrator"
48
+ option.
50
49
51
50
## What Is a Session?
52
51
53
- A session is an environment in which Windows PowerShell runs.
52
+ A session is an environment in which PowerShell runs.
54
53
55
- Each time you start Windows PowerShell, a session is created for you, and you
56
- can run commands in the session. You can also add items to your session, such
57
- as modules and snap-ins, and you can create items, such as variables,
58
- functions, and aliases. These items exist only in the session and are deleted
59
- when the session ends.
54
+ Each time you start PowerShell, a session is created for you, and you can run
55
+ commands in the session. You can also add items to your session, such as
56
+ modules and snap-ins, and you can create items, such as variables, functions ,
57
+ and aliases. These items exist only in the session and are deleted when the
58
+ session ends.
60
59
61
- You can also create user-managed sessions, known as " Windows PowerShell
62
- sessions" or "PSSessions," on the local computer or on a remote computer. Like
63
- the default session, you can run commands in a PSSession and add and create
64
- items. However, unlike the session that starts automatically, you can control
65
- the PSSessions that you create. You can get, create, configure, and remove
66
- them, disconnect and reconnect to them, and run multiple commands in the same
67
- PSSession. The PSSession remains available until you delete it or it times
68
- out.
60
+ You can also create user-managed sessions, known as "PowerShell sessions" or
61
+ "PSSessions," on the local computer or on a remote computer. Like the default
62
+ session, you can run commands in a PSSession and add and create items.
63
+ However, unlike the session that starts automatically, you can control the
64
+ PSSessions that you create. You can get, create, configure, and remove them,
65
+ disconnect and reconnect to them, and run multiple commands in the same
66
+ PSSession. The PSSession remains available until you delete it or it times out.
69
67
70
68
Typically, you create a PSSession to run a series of related commands on a
71
- remote computer. When you create a PSSession on a remote computer, Windows
72
- PowerShell establishes a persistent connection to the remote computer to
73
- support the session.
69
+ remote computer. When you create a PSSession on a remote computer, PowerShell
70
+ establishes a persistent connection to the remote computer to support the
71
+ session.
74
72
75
73
If you use the ** ComputerName** parameter of the ` Invoke-Command ` or
76
74
` Enter-PSSession ` cmdlet to run a remote command or to start an interactive
77
- session, Windows PowerShell creates a temporary session on the remote computer
78
- and closes the session as soon as the command is complete or as soon as the
75
+ session, PowerShell creates a temporary session on the remote computer and
76
+ closes the session as soon as the command is complete or as soon as the
79
77
interactive session ends. You cannot control these temporary sessions, and you
80
- cannot use them for more than a single command or a single interactive
81
- session.
78
+ cannot use them for more than a single command or a single interactive session.
82
79
83
- In Windows PowerShell, the "current session" is the session that you are
84
- working in. The "current session" can refer to any session, including a
85
- temporary session or a PSSession.
80
+ In PowerShell, the "current session" is the session that you are working in.
81
+ The "current session" can refer to any session, including a temporary session
82
+ or a PSSession.
86
83
87
84
## Why Use a PSSession?
88
85
@@ -96,10 +93,9 @@ You can run remote commands without creating a PSSession. Use the
96
93
or a series of unrelated commands on one or many computers.
97
94
98
95
When you use the ** ComputerName** parameter of ` Invoke-Command ` or
99
- ` Enter-PSSession ` , Windows PowerShell establishes a temporary connection to
100
- the remote computer and then closes the connection as soon as the command is
101
- complete. Any data elements that you create are lost when the connection is
102
- closed.
96
+ ` Enter-PSSession ` , PowerShell establishes a temporary connection to the remote
97
+ computer and then closes the connection as soon as the command is complete.
98
+ Any data elements that you create are lost when the connection is closed.
103
99
104
100
Other cmdlets that have a ** ComputerName** parameter, such as ` Get-Eventlog `
105
101
and ` Get-WmiObject ` , use different remoting technologies to gather data. None
@@ -108,8 +104,8 @@ create a persistent connection like a PSSession.
108
104
## How to Create a PSSession
109
105
110
106
To create a PSSession, use the ` New-PSSession ` cmdlet. To create the PSSession
111
- on a remote computer, use the ** ComputerName** parameter of the
112
- ` New-PSSession ` cmdlet.
107
+ on a remote computer, use the ** ComputerName** parameter of the ` New-PSSession `
108
+ cmdlet.
113
109
114
110
For example, the following command creates a new PSSession on the Server01
115
111
computer.
@@ -151,7 +147,8 @@ To get the PSSessions that were created in your current session, use the
151
147
` Get-PSSession ` cmdlet without the ** ComputerName** parameter. ` Get-PSSession `
152
148
returns the same type of object that ` New-PSSession ` returns.
153
149
154
- The following command gets all the PSSessions that were created in the current session.
150
+ The following command gets all the PSSessions that were created in the current
151
+ session.
155
152
156
153
``` powershell
157
154
Get-PSSession
@@ -239,7 +236,7 @@ until it times out.
239
236
240
237
You can also use the ** IdleTimeout** parameter of the ` New-PSSessionOption `
241
238
cmdlet to set an expiration time for an idle PSSession. For more information,
242
- see [ New-PSSessionOption] ( xref:Microsoft.PowerShell.Core.New-PSSessionOption ) .
239
+ see [ New-PSSessionOption] [ 03 ] .
243
240
244
241
## The PSSession Cmdlets
245
242
@@ -261,18 +258,33 @@ Get-Help *-PSSession
261
258
262
259
## For More Information
263
260
264
- For more information about PSSessions, see [ about_PSSession_Details] ( about_PSSession_Details.md ) .
261
+ For more information about PSSessions, see [ about_PSSession_Details] [ 01 ] .
265
262
266
263
## See also
267
264
268
- - [ about_Remote] ( about_Remote.md )
269
- - [ about_Remote_Disconnected_Sessions] ( about_Remote_Disconnected_Sessions.md )
270
- - [ about_Remote_Requirements] ( about_Remote_Requirements.md )
271
- - [ Invoke-Command] ( xref:Microsoft.PowerShell.Core.Invoke-Command )
272
- - [ Connect-PSSession] ( xref:Microsoft.PowerShell.Core.Connect-PSSession )
273
- - [ Disconnect-PSSession] ( xref:Microsoft.PowerShell.Core.Disconnect-PSSession )
274
- - [ Enter-PSSession] ( xref:Microsoft.PowerShell.Core.Enter-PSSession )
275
- - [ Exit-PSSession] ( xref:Microsoft.PowerShell.Core.Exit-PSSession )
276
- - [ Get-PSSession] ( xref:Microsoft.PowerShell.Core.Get-PSSession )
277
- - [ New-PSSession] ( xref:Microsoft.PowerShell.Core.New-PSSession )
278
- - [ Remove-PSSession] ( xref:Microsoft.PowerShell.Core.Remove-PSSession )
265
+ - [ about_Remote] [ 05 ]
266
+ - [ about_Remote_Disconnected_Sessions] [ 04 ]
267
+ - [ about_Remote_Requirements] [ 02 ]
268
+ - [ Invoke-Command] [ 06 ]
269
+ - [ Connect-PSSession] [ 07 ]
270
+ - [ Disconnect-PSSession] [ 08 ]
271
+ - [ Enter-PSSession] [ 09 ]
272
+ - [ Exit-PSSession] [ 10 ]
273
+ - [ Get-PSSession] [ 11 ]
274
+ - [ New-PSSession] [ 12 ]
275
+ - [ Remove-PSSession] [ 13 ]
276
+
277
+ <!-- link references -->
278
+ [ 01 ] : about_PSSession_Details.md
279
+ [ 02 ] : about_Remote_Requirements.md
280
+ [ 03 ] : xref:Microsoft.PowerShell.Core.New-PSSessionOption
281
+ [ 04 ] : about_Remote_Disconnected_Sessions.md
282
+ [ 05 ] : about_Remote.md
283
+ [ 06 ] : xref:Microsoft.PowerShell.Core.Invoke-Command
284
+ [ 07 ] : xref:Microsoft.PowerShell.Core.Connect-PSSession
285
+ [ 08 ] : xref:Microsoft.PowerShell.Core.Disconnect-PSSession
286
+ [ 09 ] : xref:Microsoft.PowerShell.Core.Enter-PSSession
287
+ [ 10 ] : xref:Microsoft.PowerShell.Core.Exit-PSSession
288
+ [ 11 ] : xref:Microsoft.PowerShell.Core.Get-PSSession
289
+ [ 12 ] : xref:Microsoft.PowerShell.Core.New-PSSession
290
+ [ 13 ] : xref:Microsoft.PowerShell.Core.Remove-PSSession
0 commit comments