/// <summary>
        /// Will deploy and execute provided PowerShell script on remote server with provided options.
        /// </summary>
        /// <param name="scriptFile"></param>
        /// <param name="powerShellOptions"></param>
        /// <returns></returns>
        public static IOfferRemoteExecution PowerShell(this IOfferRemoteExecution execute, FileInfo scriptFile, Action <IOfferPowerShellOptions> powerShellOptions)
        {
            var options = new PowerShellOptions();

            powerShellOptions(options);
            var operation = new RemotePowerShellHostOperation(scriptFile, options.Values);

            Configure.Operation(execute, operation);
            return(execute);
        }
        /// <summary>
        /// Will deploy and execute provided PowerShell script on remote server.
        /// </summary>
        /// <param name="scriptFile"></param>
        /// <returns></returns>
        public static IOfferRemoteExecution PowerShell(this IOfferRemoteExecution execute, string command, Action <IOfferPowerShellOptions> powerShellOptions)
        {
            var options = new PowerShellOptions();

            powerShellOptions(options);
            var operation = new RemotePowerShellHostOperation(command, options.Values);

            Configure.Operation(execute, operation);
            return(execute);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Will deploy and execute provided PowerShell script on remote server with provided options.
        /// </summary>
        /// <param name="scriptFile"></param>
        /// <param name="powerShellOptions"></param>
        /// <returns></returns>
        public static IOfferRemoteExecution PowerShell(this IOfferRemoteExecution execute, FileInfo scriptFile, Action <IOfferPowerShellOptions> powerShellOptions)
        {
            var options = new PowerShellOptions();

            powerShellOptions(options);
            var operation = new PowerShellOperation(scriptFile, options.Values);

            OperationExecutor.Execute((RemoteBuilder)execute, operation);
            return(execute);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Will deploy and execute provided PowerShell script on remote server.
        /// </summary>
        /// <param name="scriptFile"></param>
        /// <returns></returns>
        public static IOfferRemoteExecution PowerShell(this IOfferRemoteExecution execute, string command, Action <IOfferPowerShellOptions> powerShellOptions)
        {
            var options = new PowerShellOptions();

            powerShellOptions(options);
            var operation = new PowerShellOperation(command, options.Values);

            OperationExecutor.Execute((RemoteBuilder)execute, operation);
            return(execute);
        }
Ejemplo n.º 5
0
        public PowerShellEngine(PowerShellOptions options, ILogger logger)
        {
            _options = options;
            _logger  = logger;
            Iss      = InitialSessionState.CreateDefault2();

            // Preload all cmdlets from this assembly
            Assembly core = Assembly.GetExecutingAssembly();

            Iss.LoadCmdlets(core);

            // FOR CORE:
            // Fix the PSModulePath, because now we're a full-blown host and ship with our own modules
            // TODO: What should this default be?
            var oldPath      = Environment.GetEnvironmentVariable("PSModulePath", EnvironmentVariableTarget.Process) ?? "";
            var localModules = Path.Combine(Path.GetDirectoryName(core.Location), "Modules");
            var newPath      = string.Join(Path.PathSeparator, oldPath.Split(Path.PathSeparator).Append(localModules).Distinct());

            Environment.SetEnvironmentVariable("PSModulePath", newPath, EnvironmentVariableTarget.Process);

            // We may want to use a runspace pool? ps.RunspacePool = rsp;
            Runspace = RunspaceFactory.CreateRunspace(Iss);
            Runspace.Open();
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            var loggerFactory = new LoggerFactory();

            var installPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var baseConfig  = Path.Combine(installPath, "PowerShell-Kernel.Config.json");
            var cwdConfig   = Path.Combine(Directory.GetCurrentDirectory(), "PowerShell-Kernel.Config.json");

            var configBuilder = new ConfigurationBuilder()
                                .AddJsonFile(baseConfig, true)
                                .AddJsonFile(cwdConfig, true);

            configuration = configBuilder.Build();

            var loggerOptions = new LoggerOptions();

            configuration.GetSection("Logger").Bind(loggerOptions);

            if (configuration.GetSection("Debug").GetValue <bool>("BreakOnStart"))
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
                else
                {
                    System.Diagnostics.Debugger.Launch();
                }
            }

            if (loggerOptions.ConsoleOutput)
            {
                loggerFactory.AddConsole();
            }

            if (loggerOptions.DebuggerOutput)
            {
                loggerFactory.AddDebug();
            }

            logger = loggerFactory.CreateLogger <PowerShellEngine>();

            PrintAllArgs(args);
            if (args.Length <= 0)
            {
                Console.WriteLine("Requires path to Connection file.");
                return;
            }

            ConnectionInformation connectionInformation = ConnectionInformation.FromFile(args[0]);

            var options = new PowerShellOptions();

            configuration.GetSection("PowerShell").Bind(options);

            var     engine     = new PowerShellEngine(options, logger);
            Session connection = new Session(connectionInformation, engine, logger);

            engine.AddReadOnlyVariables(("JupyterSession", connection));
            connection.Wait();

            System.Threading.Thread.Sleep(60000);
        }
Ejemplo n.º 7
0
 public ExecutionResult(PowerShellOptions options)
 {
     _options = options;
 }