63 lines
3.3 KiB
Plaintext
63 lines
3.3 KiB
Plaintext
Remoting Disconnect Reconnect Sample 01
|
|
=======================================
|
|
This sample shows how to construct a remote runspace, construct a pipeline to execute a long
|
|
running script, disconnect the runspace and pipeline, reconstruct the runspace and pipeline
|
|
state, reconnect the runspace and pipeline, and retrieve command execution state and output
|
|
data.
|
|
|
|
The sample includes two scenarios. In the first scenario, a remote runspace object and a
|
|
pipeline object are created to invoke a long-running script on the remote server. While the
|
|
script is running, the remote runspace and pipeline objects are disconnected. The same remote
|
|
runspace and pipeline objects are then reconnected to the server to obtain status information
|
|
and output data generated by the script.
|
|
|
|
In the second scenario, a new pipeline object is created using the runspace created in the
|
|
previous scenario, and the same long-running script is invoked. The remote runspace and
|
|
pipeline are disconnected while the script runs on the remote host. In this scenario, the
|
|
remote runspace and pipeline objecs are disposed while in the disconnected state. The remote
|
|
runspace and pipeline objects are then reconstructed based on information from the remote host
|
|
session. The remote runspace and pipeline objects are connected to the server to obtain status
|
|
information and output data from the running script.
|
|
|
|
For Windows PowerShell information on MSDN, see http://go.microsoft.com/fwlink/?LinkID=178145
|
|
|
|
|
|
Sample Objectives
|
|
=================
|
|
This sample demonstrates the following:
|
|
|
|
1. Creating an instance of the WSManConnectionInfo class.
|
|
2. Using this WSManConnectionInfo instance to establish a remote connection using a remote runspace object.
|
|
3. Creating a pipeline to start a long running script.
|
|
4. Disconnecting the runspace and pipeline and allowing the script to continue running on the server.
|
|
5. Reconnecting the runspace and pipeline to the script running on the server.
|
|
6. Reconstructing a runspace and pipeline for the script running on the server.
|
|
7. Getting runspace and pipeline states and retrieving script output data.
|
|
8. Closing the remote connection.
|
|
|
|
|
|
Sample Language Implementations
|
|
===============================
|
|
This sample is available in the following language implementations:
|
|
|
|
- C#
|
|
|
|
|
|
Building the Sample Using Visual Studio
|
|
=======================================
|
|
1. Open Windows Explorer and navigate to the RemotingDisconnectConnect01 directory under the samples directory.
|
|
2. Double-click the icon for the .sln (solution) file to open the file in Visual Studio.
|
|
3. Make sure the project references the System.Management.Automation.dll assembly.
|
|
4. In the Build menu, select Build Solution.
|
|
5. The executable will be built in the default \bin or \bin\Debug directory.
|
|
|
|
|
|
Running the Sample
|
|
==================
|
|
1. Verify that Windows PowerShell remoting is enabled. You can run the the following command
|
|
for additional information about how to enable this feature: help about_remote.
|
|
2. Start the Command Prompt as Administrator.
|
|
3. Navigate to the folder containing the sample executable.
|
|
4. Run the executable.
|
|
5. See the output results and the corresponding code.
|