private void AddInstallCommands(PowerShell powerShell)
 {
     powerShell.AddVariable(CredentialVariablename, _credential);
     powerShell.AddVariable(RemoteToolSourcePath, _debuggerToolLocalPath);
     powerShell.AddScript("$ErrorActionPreference = \"Stop\"");
     powerShell.AddScript("$sessionOptions = New-PSSessionOption –SkipCACheck –SkipCNCheck –SkipRevocationCheck");
     powerShell.AddScript($"$session = New-PSSession {_computerName} -UseSSL -Credential $credential -SessionOption $sessionOptions");
     powerShell.AddScript(RemotePowerShellUtils.GetEmbeddedFile(InstallerPsFilePath));
     powerShell.AddScript("Remove-PSSession -Session $session");
 }
        /// <summary>
        /// Start the session and start the remote tool.
        /// This starts a backgroud task and leave it running till it is cancelled or stopped.
        /// </summary>
        /// <param name="computerName">The ipaddress of debugging target machine.</param>
        /// <param name="username">The username for authentication.</param>
        /// <param name="password">The password for authentication.</param>
        /// <param name="subscribeClosingEvent">The method to subscribe to solution closing event.</param>
        /// <param name="unsubscribeClosingEvent">The method to unsubscribe solution closing event.</param>
        public RemoteToolSession(
            string computerName,
            string username,
            string password,
            Action <EventHandler> subscribeClosingEvent,
            Action <EventHandler> unsubscribeClosingEvent)
        {
            var    target = new RemoteTarget(computerName, RemotePowerShellUtils.CreatePSCredential(username, password));
            string script = RemotePowerShellUtils.GetEmbeddedFile(StartPsFilePath);

            _closingEventHandler = (se, e) => Stop();
            subscribeClosingEvent(_closingEventHandler);

            _powerShellTask = ExecuteScript(target, script, unsubscribeClosingEvent);
        }
Beispiel #3
0
        /// <summary>
        /// Start the session and start the remote tool.
        /// This starts a backgroud task and leave it running till it is cancelled or stopped.
        /// </summary>
        /// <param name="computerName">The ipaddress of debugging target machine.</param>
        /// <param name="username">The username for authentication.</param>
        /// <param name="password">The password for authentication.</param>
        /// <param name="subscribeClosingEvent">The method to subscribe to solution closing event.</param>
        /// <param name="unsubscribeClosingEvent">The method to unsubscribe solution closing event.</param>
        public RemoteToolSession(
            string computerName,
            string username,
            string password,
            Action <EventHandler> subscribeClosingEvent,
            Action <EventHandler> unsubscribeClosingEvent)
        {
            var    target = new RemoteTarget(computerName, RemotePowerShellUtils.CreatePSCredential(username, password));
            string script = RemotePowerShellUtils.GetEmbeddedFile(StartPsFilePath);

            _closingEventHandler = (se, e) => Stop();
            subscribeClosingEvent(_closingEventHandler);
            _powerShellTask = Task.Run(() =>
            {
                try
                {
                    target.EnterSessionExecute(script, _cancelTokenSource.Token);
                }
                finally
                {
                    unsubscribeClosingEvent(_closingEventHandler);
                }
            });
        }