本文整理汇总了C#中System.Management.Automation.Runspaces.Runspace.Open方法的典型用法代码示例。如果您正苦于以下问题:C# Runspace.Open方法的具体用法?C# Runspace.Open怎么用?C# Runspace.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.Runspaces.Runspace
的用法示例。
在下文中一共展示了Runspace.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PSTestScope
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();
}
}
示例2: WishModel
public WishModel()
{
_runspace = RunspaceFactory.CreateRunspace();
_runspace.Open();
_runner = new Powershell(_runspace);
_repl = new Repl(_runner);
}
示例3: HookInjection
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);
}
}
示例4: ScriptDebugger
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);
}
示例5: RawExecute
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;
}
示例6: InitializeTests
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];
}
}
示例7: createRunspace
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
}
示例8: ExchPowershell
/// <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);
}
}
示例9: AppFabricPowershellCommandRunner
public AppFabricPowershellCommandRunner()
{
_state = InitialSessionState.CreateDefault();
_state.ImportPSModule(new string[] { "DistributedCacheAdministration", "DistributedCacheConfiguration" });
_state.ThrowOnRunspaceOpenError = true;
_runspace = RunspaceFactory.CreateRunspace(_state);
_runspace.Open();
}
示例10: PipelineFixture
public PipelineFixture()
{
var runspaceConfiguration = RunspaceConfiguration.Create();
runspaceConfiguration.Providers.Append(new ProviderConfigurationEntry(CloudProvider.PROVIDER_NAME, typeof(CloudProvider), null));
runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
}
示例11: ImportModule
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();
}
示例12: PSListenerConsoleSample
/// <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();
}
示例13: CompletionProvider
public CompletionProvider(IBackendContext backendContext, LanguageContext languageContext)
{
_languageContext = languageContext;
_backendContext = backendContext;
_snippetsCollection = AppContext.Resolve<ISnippetsCollection>();
_runspace = RunspaceFactory.CreateRunspace();
_runspace.Open();
}
示例14: AsyncPowershellRunnerForm
public AsyncPowershellRunnerForm()
{
InitializeComponent();
InitializeComboBox();
// create Powershell runspace
runSpace = RunspaceFactory.CreateRunspace();
// open it
runSpace.Open();
}
示例15: PowerShellScriptingContext
/// <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();
}