/// <summary> /// Creates a new instance of the RunspaceChangedEventArgs class. /// </summary> /// <param name="changeAction">The action which caused the runspace to change.</param> /// <param name="previousRunspace">The previously active runspace.</param> /// <param name="newRunspace">The newly active runspace.</param> public RunspaceChangedEventArgs( RunspaceChangeAction changeAction, RunspaceDetails previousRunspace, RunspaceDetails newRunspace) { Validate.IsNotNull(nameof(previousRunspace), previousRunspace); this.ChangeAction = changeAction; this.PreviousRunspace = previousRunspace; this.NewRunspace = newRunspace; }
/// <summary> /// Creates a clone of the given runspace through which another /// runspace was attached. Sets the IsAttached property of the /// resulting RunspaceDetails object to true. /// </summary> /// <param name="runspaceDetails"> /// The RunspaceDetails object which the new object based. /// </param> /// <param name="runspaceContext"> /// The RunspaceContext of the runspace. /// </param> /// <param name="sessionDetails"> /// The SessionDetails for the runspace. /// </param> /// <returns> /// A new RunspaceDetails instance for the attached runspace. /// </returns> public static RunspaceDetails CreateFromContext( RunspaceDetails runspaceDetails, RunspaceContext runspaceContext, SessionDetails sessionDetails) { return (new RunspaceDetails( runspaceDetails.Runspace, sessionDetails, runspaceDetails.PowerShellVersion, runspaceDetails.Location, runspaceContext, runspaceDetails.ConnectionString)); }
/// <summary> /// Creates a new RunspaceDetails object from a remote /// debugging session. /// </summary> /// <param name="runspaceDetails"> /// The RunspaceDetails object which the new object based. /// </param> /// <param name="runspaceLocation"> /// The RunspaceLocation of the runspace. /// </param> /// <param name="runspaceContext"> /// The RunspaceContext of the runspace. /// </param> /// <param name="sessionDetails"> /// The SessionDetails for the runspace. /// </param> /// <returns> /// A new RunspaceDetails instance for the attached runspace. /// </returns> public static RunspaceDetails CreateFromDebugger( RunspaceDetails runspaceDetails, RunspaceLocation runspaceLocation, RunspaceContext runspaceContext, SessionDetails sessionDetails) { // TODO: Get the PowerShellVersion correctly! return (new RunspaceDetails( runspaceDetails.Runspace, sessionDetails, runspaceDetails.PowerShellVersion, runspaceLocation, runspaceContext, runspaceDetails.ConnectionString)); }
public static DscBreakpointCapability CheckForCapability( RunspaceDetails runspaceDetails, PowerShellContextService powerShellContext, ILogger logger) { DscBreakpointCapability capability = null; // DSC support is enabled only for Windows PowerShell. if ((runspaceDetails.PowerShellVersion.Version.Major < 6) && (runspaceDetails.Context != RunspaceContext.DebuggedRunspace)) { using (PowerShell powerShell = PowerShell.Create()) { powerShell.Runspace = runspaceDetails.Runspace; // Attempt to import the updated DSC module powerShell.AddCommand("Import-Module"); powerShell.AddArgument(@"C:\Program Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1"); powerShell.AddParameter("PassThru"); powerShell.AddParameter("ErrorAction", "Ignore"); PSObject moduleInfo = null; try { moduleInfo = powerShell.Invoke().FirstOrDefault(); } catch (RuntimeException e) { logger.LogException("Could not load the DSC module!", e); } if (moduleInfo != null) { logger.LogTrace("Side-by-side DSC module found, gathering DSC resource paths..."); // The module was loaded, add the breakpoint capability capability = new DscBreakpointCapability(); runspaceDetails.AddCapability(capability); powerShell.Commands.Clear(); powerShell .AddCommand("Microsoft.PowerShell.Utility\\Write-Host") .AddArgument("Gathering DSC resource paths, this may take a while...") .Invoke(); // Get the list of DSC resource paths powerShell.Commands.Clear(); powerShell .AddCommand("Get-DscResource") .AddCommand("Select-Object") .AddParameter("ExpandProperty", "ParentPath"); Collection <PSObject> resourcePaths = null; try { resourcePaths = powerShell.Invoke(); } catch (CmdletInvocationException e) { logger.LogException("Get-DscResource failed!", e); } if (resourcePaths != null) { capability.dscResourceRootPaths = resourcePaths .Select(o => (string)o.BaseObject) .ToArray(); logger.LogTrace($"DSC resources found: {resourcePaths.Count}"); } else { logger.LogTrace($"No DSC resources found."); } } else { logger.LogTrace($"Side-by-side DSC module was not found."); } } } return(capability); }