Questions tagged [pscmdlet]

Serves as a base class for derived commandlets that depend on access to the Windows PowerShell runtime, and therefore execute within a runspace.

PScmdlet requires and has access to the Windows PowerShell runtime, which allows the cmdlet to call scripts, access Windows PowerShell providers, and access the current session state.

50 questions
7
votes
0 answers

How to set help information for pscmdlet class

I'm writing a powershell module in c# that's comprised of a bunch of powershell cmdlets. for example: get-application When I declare the class [Cmdlet(VerbsCommon.Get, "Application")] public class GetApplication : PSCmdlet I can do things…
anoopb
  • 493
  • 3
  • 6
  • 18
7
votes
1 answer

Returning an object from PowerShell cmdlet

I'm trying to create my own set of cmdlets for a PowerShell snapin. The problem I'm having is that I've created my own object that I create and populate within the ProcessRecord method but I'm not able to change the return type to allow me to return…
user1865044
  • 181
  • 2
  • 9
6
votes
2 answers

How to add synopsis/summary for a cmdlet in C#?

Suppose you are writing some PSCmdLet in C#: /// /// Get a stack overflow exception. /// [Cmdlet(VerbsCommon.Join, "StackOverflow")] [OutputType(typeof(OverflowException))] public class JoinStackOverflow : PSCmdlet { protected…
Rok Strniša
  • 6,085
  • 6
  • 37
  • 48
5
votes
2 answers

Powershell Cmdlet.ShouldProcess Method default answer

I have a powershell script in which I have implemented the should process method with a high ConfirmImpact to ensure a prompt occurs. Prompting is working as expected however the default response when nothing is entered is "Y" [Y] Yes [A] Yes to…
Jessie
  • 250
  • 2
  • 10
3
votes
0 answers

custom cmdlet entry in remote powershell

I have been trying for days to add my custom cmdlet to the runspace of a remote powershell in C# string shellUri = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell"; System.Security.SecureString sString = new…
S. Schenkel
  • 141
  • 7
3
votes
1 answer

Detecting a PowerShell Switch

I'm developing a PowerShell cmdlet in C#, and have true/false switch statements. I have noted that I need to specify -SwitchName $true, if I want the bool to be true, otherwise I get: Missing an argument for parameter 'SwitchName'. Specify a…
Trevor Seward
  • 277
  • 1
  • 5
  • 20
3
votes
1 answer

PSCmdlet dynamic auto complete a parameter (like Get-Process)

In powershell some parameter have a dynamic auto complete behavior. For Example, Get-Process the parameter Name. I can iterate trough all my processes with TAB. I want to use this behavior in my PSCmdlet. But the problem is, I only know how to do…
hdev
  • 5,399
  • 1
  • 41
  • 55
3
votes
3 answers

Powershell: Update-TfsWorkspace cmdlet how to update two workspaces

I want to update 2 workspaces from two different tfs in one script using powershell. The first Workspace is updating without any Problems. After the update is finished powershell connects to the second Workspace, but isn't updating the local data…
Zittelrittel
  • 61
  • 1
  • 7
3
votes
2 answers

How to hide a parameter in Cmdlet

I want to hide a PowerShell Cmdlet parameter from user. Is there any way to do this in C#? I want to use this parameter within my code to trigger the same cmdlet with the hidden parameter. I use PowerShell 2.0. Thanks.
Hem
  • 421
  • 8
  • 22
3
votes
1 answer

PSCmdlet calling other command freezes due to long processing time?

I have a PSCmdlet written in C# and .NET 3.5 that calls a few other commands that are defined within the same Cmdlet. One of these commands kicks off a full crawl on my SharePoint site and waits for it to complete. Optimistically, these take 5-10…
tnw
  • 12,391
  • 15
  • 64
  • 108
2
votes
2 answers

Cmdlet C# finalization

So I'm working with cmdlets in C# and using a base cmdlet which derives from PSCmdlet. Like this: Child <- Parent <- PSCmdlet. We login to a system using methods in the Parent cmdlet. But sometimes things don't always go right with exceptions,…
YanerTavuz
  • 31
  • 5
2
votes
1 answer

Writing a C# PowerShell cmdlet - how to output debug logging to TeamCity caller

I am writing a PowerShell cmdlet in C#, and I need to add some diagnostic logging to the script so that I can evaluate the behavior through TeamCity. Having experimented with WriteVerbose with the -Verbose flag enabled for the function, nothing was…
Dech
  • 1,284
  • 3
  • 13
  • 28
2
votes
0 answers

How to avoid WriteVerbose/WriteObject bad thread

I've created a .NET assembly with five or six PSCmdlet's in them. They are all pipe-line cmdlets - that is they have setup in BeginProcessing, and do the work in ProcessRecord. They call into a library. I use "Trace.WriteLine" throughout the library…
Gordon
  • 2,600
  • 2
  • 21
  • 31
2
votes
1 answer

How to make PSCmdlet bool parameter to work like a flag?

Using System.Management.Automation you can create custom PSCmdlets in C#. Now if you create boolean parameter like this: [Parameter()] public bool ShowDefinition { get; set; } You have to invoke cmdlet like this: PS> Get-CustomValues…
mswietlicki
  • 1,333
  • 11
  • 16
2
votes
1 answer

Cmdlet pass a list of parameters at once through a Pipeline, not individual list items

I am creating a Powershell System.Management.AutomationCmdlet.Cmdlet for passing a list of strings through a Pipeline to a Cmdlet this way: [Cmdlet(VerbsCommon.Add, "Signature")] public class AddSignature : Cmdlet ... …
Pinte Dani
  • 1,591
  • 2
  • 22
  • 31
1
2 3 4