Tags "cmdlet" Result

How to programmatically add a PSCmdlet to a Powershell pipeline?

I'd like to programmatically assemble and run a pipeline containing my own PSCmdlet. However, the Pipeline class only allows to add strings and Commands (which are constructed from strings in turn). var runspace = ...; var pipeline = runspace.CreatePipeline(); pipeline.AddCommand("Get-Date"); // ok var myCmdlet = new MyCmdlet(); pipeline.AddComman

it1352 0 2019-05-10

Is there a way pass a Cmdlet with some parameters to another Cmdlet that pipes the remaining parameters to it?

Building on this technique to use Cmdlets as "delegates" I am left with this question: Is there a way to pass a commandlet with prescribed named or positional parameters to another commandlet that uses the powershell pipeline to bind the remaining parameters to the passed commandlet? Here is the code snippet I'd like to be able to run: Functio

it1352 0 2019-05-15

How to run script on BITS download completion

I am trying to automate the download and installation of a large application that is several hundreds of MB to a few GB in size. I am looking into using BITS and powershell to asynchronously download the application and then launch the setup. Using the deprecated bitsadmin command there is a /SETNOTIFYCMDLINEoption that would allow me to chain th

it1352 1 2020-07-29

PowerShell - How do I call a cmdlet in a function when overriding that cmdlet's name with the same name as the function?

So I have a cmdlet named update-name that I have no access to change. I have created a function named update-name (the same name as the cmdlet). How do I call the cmdlet from the function with the same name? I've tried a few things and none of them seem to work. function update-name { param([string] something) #call cmdlet update-name here }

it1352 1 2020-07-05

PowerShell cmdlet parameter validation

I'm writing a custom PowerShell cmdlet, and I would like to know which is the proper way to validate a parameter. I thought that this could be done either in the property set accessor or during Cmdlet execution: [Cmdlet(VerbsCommon.Add,"X")] public class AddX : Cmdlet { private string _name; [Parameter( Mandatory=false, H

it1352 1 2019-05-10

How do I use NUnit in VSTS?

I am trying to use NUnit 3 within Visual Studio Team System which they seem to have made really hard. I have added in a test assemblies step to the build process and in Advanced execution options -> Path to Custom Test Adapters, I have put in the directory path to NUnitVisualStudioTestAdapter-2.0.0.vsix plugin as advised in the help. No matter wha

it1352 1 2020-09-17

How to convert .cs file to a powershell cmdlet

Can anyone help me to convert a c# .net program to powershell cmdlet. I am very new to this area. plz help me to get out of this checkpoint. Regards Arun Solution Add a reference to System.Management.Automation, create a class that inherits from Cmdlet and override the ProcessRecord method: [Cmdlet(VerbsCommon.Get, "Double")] public class GetDo

it1352 0 2019-05-10

How can I get the current directory in PowerShell cmdlet?

I am developing a PowerShell 3.0 cmdlet using C#/.Net 4.0 in Visual Studio 2010. I'd like to get the current directory in PowerShell where the user executes the cmdlet. But Directory.GetCurrentDirectory() doesn't work as expected. In the code below, the result is C:\Users\Administrator. Question: What cmdlet code is used to get PowerShell's curre

it1352 2 2019-05-10