public void TestAddParameters() { PowerShellWrapper newPowerShellWrapper = new PowerShellWrapper(); newPowerShellWrapper.AddCommand("Get-Command"); newPowerShellWrapper.AddParameter("Test", "Test"); }
public void TestInstantiation() { PowerShellWrapper newPowerShellWrapper = new PowerShellWrapper(); Assert.IsNotNull(newPowerShellWrapper); Assert.IsInstanceOfType(newPowerShellWrapper, typeof(PowerShellWrapper)); }
public override IEnumerable <CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters) { var values = new List <CompletionResult>(); // If the user has explicitly added the -subDomain parameter // to the command use that to filter the results. var subDomain = fakeBoundParameters["subDomain"]?.ToString(); // To complete resources you have to provide the area first var area = fakeBoundParameters["area"]?.ToString(); var spat = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(subDomain)) { spat.Add("subDomain", subDomain); } this._powerShell.Commands.Clear(); if (string.Compare(parameterName, "Area", true) == 0) { var areas = this._powerShell.AddCommand("Get-VSTeamOption") .AddParameters(spat) .AddCommand("Select-Object") .AddParameter("ExpandProperty", "Area") .AddParameter("Unique") .AddCommand("Sort-Object") .Invoke <string>(); PowerShellWrapper.LogPowerShellError(this._powerShell, areas); SelectValues(wordToComplete, areas, values); } else if (!string.IsNullOrEmpty(area)) { var resources = this._powerShell.AddCommand("Get-VSTeamOption") .AddParameters(spat) .AddCommand("Where-Object") .AddParameter("Property", "area") .AddParameter("-EQ") .AddParameter("Value", area) .AddCommand("Select-Object") .AddParameter("ExpandProperty", "ResourceName") .AddParameter("Unique") .AddCommand("Sort-Object") .Invoke <string>(); PowerShellWrapper.LogPowerShellError(this._powerShell, resources); SelectValues(wordToComplete, resources, values); } return(values); }
public void TestDisposeMethod() { PowerShellWrapper newPowerShellWrapper = new PowerShellWrapper(); newPowerShellWrapper.AddCommand("Get-Command"); newPowerShellWrapper.AddParameter("Test", "Test"); newPowerShellWrapper.Dispose(); }
public void UsePowerShell() { if (powerShellWrapper == null) { powerShellWrapper = new PowerShellWrapper(targetDevice.HostName); powerShellWrapper.InvocationStateChanged -= SessionStateChanged; powerShellWrapper.InvocationStateChanged += SessionStateChanged; } }
public void TestInvokeMethod() { PowerShellWrapper newPowerShellWrapper = new PowerShellWrapper(); newPowerShellWrapper.AddCommand("Get-Command"); newPowerShellWrapper.AddParameter("Test", "Test"); Collection <PSObject> returnedObjects = newPowerShellWrapper.Invoke(); Assert.IsTrue(returnedObjects.Count > 0); }
public static string GetDefaultProject(IPowerShell powerShell) { powerShell.Commands.Clear(); var results = powerShell.AddScript("$Global:PSDefaultParameterValues[\"*-vsteam*:projectName\"]") .Invoke <string>(); PowerShellWrapper.LogPowerShellError(powerShell, results); return(results[0]); }
protected override object[] GetChildren() { this.PowerShell.Commands.Clear(); var children = this.PowerShell.AddCommand(this.Command) .AddParameter("PoolId", this.PoolId) .AddParameter("AgentId", this.AgentId) .Invoke(); PowerShellWrapper.LogPowerShellError(this.PowerShell, children); return(children.AddTypeName(this.TypeName)); }
protected override object[] GetChildren() { this.PowerShell.Commands.Clear(); var children = this.PowerShell.AddCommand(this.Command) .AddParameter("PoolId", this.Id) .Invoke(); PowerShellWrapper.LogPowerShellError(this.PowerShell, children); // This is important so the correct formatting is applied return(children.AddTypeName(this.TypeName)); }
/// <summary> /// Internal entry into the automation framework. /// </summary> /// <param name="passedCommand">Command to be run.</param> /// <param name="testing">Boolean to determine if this is being called by a test method.</param> /// <param name="servers">The servers to run the commands against.</param> /// <param name="parameter">Name of the Parameter.</param> /// <param name="value">Value of the parameter.</param> public void DoAutomationWork(Commands passedCommand, bool testing, string[] servers, string parameter, string value) { // As the number of servers could be in the hundreds, // we parallel the execution so that the tasks may be performed // "simultaneously". See the reference source for Parallel.ForEach // for details on how "simultaneous" may not be the case. Parallel.ForEach( servers, (x) => { PowerShellWrapper newPowerShellWrapper = new PowerShellWrapper(); this.BeginPowerShellWork(newPowerShellWrapper.Create, testing, passedCommand, x, parameter, value); }); }
protected override object[] GetChildren() { this.PowerShell.Commands.Clear(); var children = this.PowerShell.AddCommand(this.Command) .AddParameter("ProjectName", this.ProjectName) .AddParameter("RepositoryId", this.Id) .AddCommand("Sort-Object") .AddArgument("name") .Invoke(); PowerShellWrapper.LogPowerShellError(this.PowerShell, children); // This applies types to select correct formatter. return(children.AddTypeName(this.TypeName)); }
protected override IEnumerable <PSObject> GetPSObjects() { this.PowerShell.Commands.Clear(); var children = this.PowerShell.AddCommand(this.Command) .AddParameter("ProjectName", this.ProjectName) .AddParameter("Expand", "Environments") .AddCommand("Sort-Object") .AddArgument("name") .Invoke(); PowerShellWrapper.LogPowerShellError(this.PowerShell, children); // This applies types to select correct formatter. return(children.AddTypeName(this.TypeName)); }
public static string RunPowerShell(string options) { options = Uri.UnescapeDataString(options); PowerShellWrapper pswrapper = new PowerShellWrapper(); Dictionary <string, string> optionDict; if (!string.IsNullOrEmpty(options)) { optionDict = parseOptions(options); } else { optionDict = null; } return(pswrapper.runPowerShell(options, optionDict)); }
private void Window_Loaded(object sender, RoutedEventArgs e) { var modules = new string[] { @"D:\TestModule.psm1" }; ps = new PowerShellWrapper(modules); var results = ps.InvokeSynchronous(@"dir c:\"); foreach (var directory in results) { cmbDirectories.Items.Add(directory); } var currentDate = ps.InvokeSynchronous(@"(Get-Date).AddMonths(3)"); calCalendar.DisplayDate = (DateTime)currentDate[0].BaseObject; }
/// <summary> /// Completers that need the project name to call the correct function must /// implement this overload of GetValue /// </summary> /// <param name="projectName">Name of the project to use</param> /// <returns>A list of strings</returns> internal virtual IEnumerable <string> GetValues(string projectName) { this._powerShell.Commands.Clear(); var results = this._powerShell.AddCommand(this._command) .AddParameter("ProjectName", projectName) .AddCommand("Select-Object") .AddParameter("ExpandProperty", this._property) .AddParameter("Unique") .AddCommand("Sort-Object") .AddParameter("Descending", this._descending) .Invoke <string>(); PowerShellWrapper.LogPowerShellError(this._powerShell, results); return(results); }
protected override IEnumerable <PSObject> GetPSObjects() { this.PowerShell.Commands.Clear(); // We have to call this again because the amount of data you get back when you pass in the // Id must greater than when you don't. var children = this.PowerShell.AddCommand(this.Command) .AddParameter("ProjectName", this.ProjectName) .AddParameter("id", this.Id) .AddParameter("Expand", "Environments") .AddCommand("Select-Object") .AddParameter("ExpandProperty", "Environments") .Invoke(); PowerShellWrapper.LogPowerShellError(this.PowerShell, children); // This applies types to select correct formatter. return(children.AddTypeName("vsteam_lib.Provider.Environment")); }
public static VirtualHardDisk VhdGet(this ICakeContext context, FilePath vhdPath) { var vhdFullPath = vhdPath.MakeAbsolute(context.Environment).FullPath; return(PowerShellWrapper.Call_GetVHD(vhdFullPath)); }
public static void VhdMount(this ICakeContext context, FilePath vhdPath, bool readOnly) { var vhdFullPath = vhdPath.MakeAbsolute(context.Environment).FullPath; PowerShellWrapper.Call_MountVHD(vhdFullPath, readOnly); }
public void TestAddCommands() { PowerShellWrapper newPowerShellWrapper = new PowerShellWrapper(); newPowerShellWrapper.AddCommand("Get-Command"); }
public static void VhdDismount(this ICakeContext context, FilePath vhdPath) { var vhdFullPath = vhdPath.MakeAbsolute(context.Environment).FullPath; PowerShellWrapper.Call_DismountVHD(vhdFullPath); }
public static void VhdInitialize(this ICakeContext context, VirtualHardDisk vhd) { PowerShellWrapper.Call_InitializeDisk(vhd.DiskNumber); }
public static void VhdOptimize(this ICakeContext context, FilePath vhdPath, VhdCompactMode compactMode) { var vhdFullPath = vhdPath.MakeAbsolute(context.Environment).FullPath; PowerShellWrapper.Call_OptimizeVHD(vhdFullPath, compactMode); }
public static void VhdFormat(this ICakeContext context, Partition partition, FileSystemType fileSystem) { PowerShellWrapper.Call_FormatVolume(partition, fileSystem); }
public static void VhdResize(this ICakeContext context, FilePath vhdPath, ulong size) { var vhdFullPath = vhdPath.MakeAbsolute(context.Environment).FullPath; PowerShellWrapper.Call_ResizeVHD(vhdFullPath, size); }
public static void VhdAddAccessPath(this ICakeContext context, Partition partition, FilePath accessPath) { var accessFullPath = accessPath.MakeAbsolute(context.Environment).FullPath; PowerShellWrapper.Call_AddPartitionAccessPath(partition, accessFullPath); }
public static VirtualHardDisk VhdCreate(this ICakeContext context, FilePath vhdPath, ulong size, uint blockSize, VhdType vhdType) { var vhdFullPath = vhdPath.MakeAbsolute(context.Environment).FullPath; return(PowerShellWrapper.Call_NewVHD(vhdFullPath, size, blockSize, vhdType)); }
public static Partition VhdGetPartition(this ICakeContext context, VirtualHardDisk vhd) { return(PowerShellWrapper.Call_NewPartition(vhd.DiskNumber)); }
public static void VhdResizePartition(this ICakeContext context, Partition partition) { var maxSize = PowerShellWrapper.Call_GetPartitionSupportedSize(partition); PowerShellWrapper.Call_ResizePartition(partition, maxSize); }