public PSTestScope(bool connect = true) { SiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"]; CredentialManagerEntry = ConfigurationManager.AppSettings["SPOCredentialManagerLabel"]; var iss = InitialSessionState.CreateDefault(); if (connect) { SessionStateCmdletEntry ssce = new SessionStateCmdletEntry("Connect-SPOnline", typeof(ConnectSPOnline), null); iss.Commands.Add(ssce); } _runSpace = RunspaceFactory.CreateRunspace(iss); _runSpace.Open(); if (connect) { var pipeLine = _runSpace.CreatePipeline(); Command cmd = new Command("connect-sponline"); cmd.Parameters.Add("Url", SiteUrl); if (!string.IsNullOrEmpty(CredentialManagerEntry)) { cmd.Parameters.Add("Credentials", CredentialManagerEntry); } pipeLine.Commands.Add(cmd); pipeLine.Invoke(); } }
public WishModel() { _runspace = RunspaceFactory.CreateRunspace(); _runspace.Open(); _runner = new Powershell(_runspace); _repl = new Repl(_runner); }
public ScriptDebugger(bool overrideExecutionPolicy, DTE2 dte2) { HostUi = new HostUi(this); InitialSessionState iss = InitialSessionState.CreateDefault(); iss.ApartmentState = ApartmentState.STA; iss.ThreadOptions = PSThreadOptions.ReuseThread; _runspace = RunspaceFactory.CreateRunspace(this, iss); _runspace.Open(); _runspaceRef = new RunspaceRef(_runspace); //TODO: I think this is a v4 thing. Probably need to look into it. //_runspaceRef.Runspace.Debugger.SetDebugMode(DebugModes.LocalScript | DebugModes.RemoteScript); //Provide access to the DTE via PowerShell. //This also allows PoshTools to support StudioShell. _runspace.SessionStateProxy.PSVariable.Set("dte", dte2); ImportPoshToolsModule(); LoadProfile(); if (overrideExecutionPolicy) { SetupExecutionPolicy(); } SetRunspace(Runspace); }
public static Collection<PSObject> RawExecute(string[] commands) { LastRawResults = null; LastUsedRunspace = InitialSessionState == null ? RunspaceFactory.CreateRunspace() : RunspaceFactory.CreateRunspace(InitialSessionState); LastUsedRunspace.Open(); foreach (var command in commands) { using (var pipeline = LastUsedRunspace.CreatePipeline()) { pipeline.Commands.AddScript(command, true); try { LastRawResults = pipeline.Invoke(); } catch (Exception) { LastRawResults = pipeline.Output.ReadToEnd(); throw; } if (pipeline.Error.Count > 0) { throw new MethodInvocationException(String.Join(Environment.NewLine, pipeline.Error.ReadToEnd())); } } } return LastRawResults; }
public void InitializeTests() { RunspaceConfiguration config = RunspaceConfiguration.Create(); PSSnapInException warning; config.AddPSSnapIn("ShareFile", out warning); runspace = RunspaceFactory.CreateRunspace(config); runspace.Open(); // do login first to start tests using (Pipeline pipeline = runspace.CreatePipeline()) { Command command = new Command("Get-SfClient"); command.Parameters.Add(new CommandParameter("Name", Utils.LoginFilePath)); pipeline.Commands.Add(command); Collection<PSObject> objs = pipeline.Invoke(); Assert.AreEqual<int>(1, objs.Count); sfLogin = objs[0]; } }
public HookInjection( RemoteHooking.IContext InContext, String InChannelName, String entryPoint, String dll, String returnType, String scriptBlock, String modulePath, String additionalCode, bool eventLog) { Log("Opening hook interface channel...", eventLog); Interface = RemoteHooking.IpcConnectClient<HookInterface>(InChannelName); try { Runspace = RunspaceFactory.CreateRunspace(); Runspace.Open(); //Runspace.SessionStateProxy.SetVariable("HookInterface", Interface); } catch (Exception ex) { Log("Failed to open PowerShell runspace." + ex.Message, eventLog); Interface.ReportError(RemoteHooking.GetCurrentProcessId(), ex); } }
private bool createRunspace(string command) { bool result = false; // 20131210 // UIAutomation.Preferences.FromCache = false; try { testRunSpace = null; testRunSpace = RunspaceFactory.CreateRunspace(); testRunSpace.Open(); Pipeline cmd = testRunSpace.CreatePipeline(command); cmd.Invoke(); result = true; } catch (Exception eInitRunspace) { richResults.Text += eInitRunspace.Message; richResults.Text += "\r\n"; result = false; } return result; //Screen.PrimaryScreen.Bounds.Width }
/// <summary> /// Creates a new class and stores the passed values containing connection information /// </summary> /// <param name="uri">The URI to the Exchange powershell virtual directory</param> /// <param name="username">DOMAIN\Username to authenticate with</param> /// <param name="password">Password for the domain user</param> /// <param name="isKerberos">True if using kerberos authentication, False if using basic authentication</param> /// <param name="domainController">The domain controller to communicate with</param> public ExchPowershell() { try { // Retrieve the settings from the database SchedulerRetrieve.GetSettings(); // Set our domain controller to communicate with this.domainController = Config.PrimaryDC; // Get the type of Exchange connection bool isKerberos = false; if (Config.ExchangeConnectionType == Enumerations.ConnectionType.Kerberos) isKerberos = true; // Create our connection this.wsConn = GetConnection(Config.ExchangeURI, Config.Username, Config.Password, isKerberos); // Create our runspace runspace = RunspaceFactory.CreateRunspace(wsConn); // Open our connection runspace.Open(); } catch (Exception ex) { // ERROR logger.Fatal("Unable to establish connection to Exchange.", ex); } }
public AppFabricPowershellCommandRunner() { _state = InitialSessionState.CreateDefault(); _state.ImportPSModule(new string[] { "DistributedCacheAdministration", "DistributedCacheConfiguration" }); _state.ThrowOnRunspaceOpenError = true; _runspace = RunspaceFactory.CreateRunspace(_state); _runspace.Open(); }
public PipelineFixture() { var runspaceConfiguration = RunspaceConfiguration.Create(); runspaceConfiguration.Providers.Append(new ProviderConfigurationEntry(CloudProvider.PROVIDER_NAME, typeof(CloudProvider), null)); runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(); }
private void ImportModule() { InitialSessionState initial = InitialSessionState.CreateDefault(); string assemblyPath = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\src\PackageManagement.PowerShellCmdlets\bin\debug\NuGet.PackageManagement.PowerShellCmdlets.dll"); initial.ImportPSModule(new string[] { assemblyPath }); _runSpace = RunspaceFactory.CreateRunspace(initial); _runSpace.Open(); }
/// <summary> /// Create this instance of the console listener. /// </summary> PSListenerConsoleSample() { // Create the host and runspace instances for this interpreter. Note that // this application doesn't support console files so only the default snapins // will be available. myHost = new MyHost(this); myRunSpace = RunspaceFactory.CreateRunspace(myHost); myRunSpace.Open(); }
public CompletionProvider(IBackendContext backendContext, LanguageContext languageContext) { _languageContext = languageContext; _backendContext = backendContext; _snippetsCollection = AppContext.Resolve<ISnippetsCollection>(); _runspace = RunspaceFactory.CreateRunspace(); _runspace.Open(); }
/// <summary> /// Initializes a new instance of the <see cref="PowerShellScriptingContext"/> class. /// </summary> public PowerShellScriptingContext() : base("PS> ") { _host = new PowerShellHost(Output); _runspace = RunspaceFactory.CreateRunspace(_host); Runspace.DefaultRunspace = _runspace; _runspace.Open(); UpdatePrompt(); }
public AsyncPowershellRunnerForm() { InitializeComponent(); InitializeComboBox(); // create Powershell runspace runSpace = RunspaceFactory.CreateRunspace(); // open it runSpace.Open(); }
public static void TestFixtureSetup(TestContext context) { Trace.TraceInformation("{0}", context.FullyQualifiedTestClassName); var config = RunspaceConfiguration.Create(); config.Cmdlets.Append(new CmdletConfigurationEntry("Start-ProcessExtended", typeof(StartProcessExtendedCmdLet), "")); runspace = RunspaceFactory.CreateRunspace(config); runspace.Open(); }
public Host(IWin32Window owner) { _owner = owner; _instanceID = Guid.NewGuid(); _hostUI = new HostUI(); _runspace = RunspaceFactory.CreateRunspace(this); _runspace.ApartmentState = ApartmentState.STA; _runspace.Open(); }
public FullHost(bool interactive) { _interactive = interactive; LocalHost = new LocalHost(true); _currentRunspace = RunspaceFactory.CreateRunspace(LocalHost); _currentRunspace.Open(); _ctrlStmtKeywordLength = Parser.ControlStatementKeywords.Max(s => s.Length); LoadProfiles(); }
public MsPowerShellHost(string[] modules) { InitialSessionState initial = InitialSessionState.CreateDefault(); initial.ImportPSModule(modules); _space = RunspaceFactory.CreateRunspace(initial); _space.Open(); _ps = PowerShell.Create(); _ps.Runspace = _space; Init(); }
/// <summary> /// Create a RunspaceInvoke for invoking commands. This uses /// a runspace with default PSSnapins. /// </summary> public RunspaceInvoke() { RunspaceConfiguration rc = RunspaceConfiguration.Create(); _runspace = RunspaceFactory.CreateRunspace(rc); _runspace.Open(); if (Runspace.DefaultRunspace == null) { Runspace.DefaultRunspace = _runspace; } }
public static void Start() { if (SettingsService.CurrentSettings.EnableCodeAnalysis) { _runspace = RunspaceFactory.CreateRunspace(); _runspace.Open(); //ScriptAnalyzer.Instance.Initialize(_runspace, new AnalyzerService()); ScriptAnalyzer.Instance.Initialize(runspace: _runspace, outputWriter: new AnalyzerService(), includeDefaultRules: true); } }
private void InitializeScript() { rspaceconfig = RunspaceConfiguration.Create(); host = new psfhost(frm); hostinterface = (psfhostinterface)host.UI; hostinterface.WriteProgressUpdate += WriteProgressUpdate; hostinterface.WriteUpdate += WriteUpdate; rspace = RunspaceFactory.CreateRunspace(host, rspaceconfig); rspace.Open(); InitializeSessionVars(); }
public FullHost() { myHost = new LocalHost(); myRunSpace = RunspaceFactory.CreateRunspace(myHost); myRunSpace.Open(); string exePath = Assembly.GetCallingAssembly().Location; string configPath = Path.Combine(Path.GetDirectoryName(exePath), "config.ps1"); Execute(configPath); }
public OutStringFormatter(int width, bool raw) { _width = width; _raw = raw; if (!raw) { _runspace = RunspaceFactory.CreateRunspace(); _runspace.Open(); } }
public ExchPowershell() { string uri = string.Format("https://{0}/powershell", ServiceSettings.ExchangeServer); this._connection = GetConnection(uri, ServiceSettings.Username, ServiceSettings.Password, ServiceSettings.ExchangeConnection == "Kerberos" ? true : false); _runspace = RunspaceFactory.CreateRunspace(_connection); _runspace.Open(); _powershell = PowerShell.Create(); _powershell.Runspace = _runspace; }
public void Init() { _executor = new PesterTestExecutor(); _runContext = new Mock<IRunContext>(); _runspace = RunspaceFactory.CreateRunspace(new TestAdapterHost()); _runspace.Open(); _powerShell = PowerShell.Create(); _powerShell.Runspace = _runspace; }
private static Runspace getRunspace() { if (runspace != null) return runspace; RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); PSSnapInException ex = null; PSSnapInInfo pSSnapInInfo = null; // Exchange 2007 try { pSSnapInInfo = runspaceConfiguration.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out ex); } catch {} // Exchange 2010 try { pSSnapInInfo = runspaceConfiguration.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out ex); } catch {} // Exchange 2013 try { pSSnapInInfo = runspaceConfiguration.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.SnapIn", out ex); } catch {} if (pSSnapInInfo != null) { Exception except = null; try { runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(); } catch (Exception exc) { except = exc; runspace.Dispose(); runspace = null; } if (except != null) throw except; } else { throw new ExchangeServerException("Couldn't initialize PowerShell Runspace"); } return runspace; }
public PSTestScope(bool connect = true) { SiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"]; CredentialManagerEntry = ConfigurationManager.AppSettings["SPOCredentialManagerLabel"]; Realm = ConfigurationManager.AppSettings["Realm"]; AppId = ConfigurationManager.AppSettings["AppId"]; AppSecret = ConfigurationManager.AppSettings["AppSecret"]; var iss = InitialSessionState.CreateDefault(); if (connect) { SessionStateCmdletEntry ssce = new SessionStateCmdletEntry("Connect-PnPOnline", typeof(ConnectOnline), null); iss.Commands.Add(ssce); } _runSpace = RunspaceFactory.CreateRunspace(iss); _runSpace.Open(); // Sets the execution policy to unrestricted. Requires Visual Studio to run in elevated mode. var pipeLine = _runSpace.CreatePipeline(); Command cmd = new Command("Set-ExecutionPolicy"); cmd.Parameters.Add("ExecutionPolicy", "Unrestricted"); cmd.Parameters.Add("Scope", "Process"); pipeLine.Commands.Add(cmd); pipeLine.Invoke(); if (connect) { pipeLine = _runSpace.CreatePipeline(); cmd = new Command("connect-pnponline"); cmd.Parameters.Add("Url", SiteUrl); if (!string.IsNullOrEmpty(CredentialManagerEntry)) { // Use Windows Credential Manager to authenticate cmd.Parameters.Add("Credentials", CredentialManagerEntry); } else { if (!string.IsNullOrEmpty("AppId") && !string.IsNullOrEmpty("AppSecret")) { // Use oAuth Token to authenticate if (!string.IsNullOrEmpty(Realm)) { cmd.Parameters.Add("Realm", Realm); } cmd.Parameters.Add("AppId", AppId); cmd.Parameters.Add("AppSecret", AppSecret); } } pipeLine.Commands.Add(cmd); pipeLine.Invoke(); } }
public Runner(string id) { _id = id; _state = InitialSessionState.CreateDefault(); _state.AuthorizationManager = null; _host = new CustomPSHost(); _runspace = RunspaceFactory.CreateRunspace(_host, _state); _runspace.Open(); }
public void InitializeTests() { RunspaceConfiguration config = RunspaceConfiguration.Create(); PSSnapInException warning; config.AddPSSnapIn("ShareFile", out warning); runspace = RunspaceFactory.CreateRunspace(config); runspace.Open(); }
public static void Main() { const int SW_HIDE = 0; const int SW_SHOW = 5; var handle = Win32.GetConsoleWindow(); // Show Window Win32.ShowWindow(handle, SW_SHOW); var amsi = new Amsi(); amsi.Bypass(); string commandArrayString = "FIXME_FUNCTIONS"; List <string> commandArray = new List <string>(commandArrayString.Split(',')); System.Management.Automation.Runspaces.Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(); runspace.Open(); System.Management.Automation.Runspaces.Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(ApplicationData.runApp()); foreach (var command in commandArray) { pipeline.Commands.AddScript(command); } runspace.SessionStateProxy.SetVariable("FormatEnumerationLimit", -1); pipeline.Commands.Add("Out-String"); System.Collections.ObjectModel.Collection <System.Management.Automation.PSObject> results = pipeline.Invoke(); runspace.Close(); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); foreach (System.Management.Automation.PSObject obj in results) { stringBuilder.AppendLine(obj.ToString()); } System.Console.WriteLine(stringBuilder.ToString()); }
public PSScriptExecutionEngine() { _psRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault()); _psRunspace.Open(); }
public virtual void Open() { runspace.Open(); }