cmdlets

What are your favorite Powershell Cmdlets?

I just found /n softwares free Powershell NetCmdlets, and after playing with them I love the functionality they bring to the command line. So it raises the question what are your favorite Cmdlets, and how do you use them? ...

Send administrative commands to my C# Windows Service using own PowerShell CmdLets

Hi, I have a C# Windows application which runs a service. I would like to leverage PowerShell in order to offer a command line management interface for administering my running service. From my point of view, I am trying to offer the same administrative interface a la Exchange 2007. Do you have any suggestion or sample code on how to ...

Can we see the source code for PowerShell cmdlets?

Hi, I'm learning some PowerShell. Is it possible to see the source code for a built-in cmdlet like Get-ChildItem? ...

Powershell cmdlets development best practices

Hi, I'm currently putting together some Powershell cmdlets. Building them is easy enough but I don't know if I'm building them in an acceptable manner (so to speak). Are there any guidelines/best practices that one should follow for passing data into the Powershell pipeline? At the moment I'm actually output a single object of type Data...

Unit Testing PSCmdlet in VS2008

I have seen several examples on unit testing powershell commandlets in NUnit. http://www.clydesdalesoftware.net/blogs/jluif/PermaLink,guid,064a378c-85c9-4d2c-9a8d-80620e97f71e.aspx or http://www.hanselman.com/blog/TestingPowerShellScriptsWithNUnit.aspx Does anyone know same way one would unit test powershel commandlets in Visual Studio ...

Cannot access a disposed object error on external class library call

Hi, I have a Windows Forms app that provisions user accounts in Exchange using Powershell and Exchange2007 cmdlets. There is only one form to this application that takes the information for the new user and then runs the Powershell commands. Like a good programmer, I just refactored the code and took all the Exchange and Active Director...

Add custom Format in Powershell SDK without SnapIn usage

Dear Friends, I am developing a .NET/C# 2.0 application which uses the PowerShell SDK for script execution. I am not using SnapIns. I am setting everything directly through PS's RunspaceConfiguration. So my problem is that I cannot add a custom format for my type Plux.ExtensionTypeInfo implemented in the application. ( Plux.Extensio...

What is a Powershell cmdlet?

Approaching cmdlets in a conceptual way, How are they made? Are they compiled? Is it the equivalent of a batch file for Powershell? Is it a script or a binary? What is the structure used for storing these cmdlets? ...

How do I determine if a PowerShell Cmdlet parameter value was specified?

In PowerShell 1.0, if I have a cmdlet parameter of an enum type, what is the recommended method for testing whether the user specified that parameter on the cmdlet command line? For example: MyEnum : int { No = 0, Yes = 1, MaybeSo = 2 } class DoSomethingCommand : PSCmdlet ... private MyEnum isEnabled; [Parameter(Mandatory = false)] p...

How do I get around PowerShell not binding pipeline parameters until after BeginProcessing is called?

I'm writing a Cmdlet that can be called in the middle of a pipeline. With this Cmdlet, there are parameters that have the ValueFromPipelineByPropertyName attribute defined so that the Cmdlet can use parameters with the same names that are defined earlier in the pipeline. The paradox that I've run into is in the overridden BeginProcessin...

How do I add a PowerShell cmdlet or function to my machine so that it is always available?

If I find (or create) a new PowerShell cmdlet (or function), how do I add it to my machine? Do I copy it to a particular folder? Do I put its content in a particular file? Do I need to authorize it, or sign it, or give it permission in some way? I don't want to use it in just one session, I want it to be available whenever I use Powers...

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...

Difference between Cmdlet.EndProcessing and Cmdlet.StopProcessing

When writing Powershell cmdlets, what is the difference between EndProcessing and StopProcessing? They sound the same, their descriptions are just about the same, and latter doesn't appear in the cmdlet lifecycle documentation. ...

Where is the "Invoke" member in System.Management.Automation.VerbsCommon?

I'm trying to create a cmdlet with the name Invoke-Something. But I cannot find the member "Invoke" to put in the attribute: [Cmdlet(VerbsCommon.Invoke, "Something", SupportsShouldProcess = true)] ^^^^^^ What am I missing? ...

Powershell - Get Variable from C# Cmdlet

I'm writing a C# Cmdlet that needs to get the value of a global script variable. How do I do it? I noticed that the Runspace has SessionStateProxy.GetVariable method. Can I access the runspace from a C# Cmdlet? Thanks! ...

How do I pass common powershell command line parameters between cmdlets on the pipeline?

Say I've got two cmdlets, 'new-foo' and 'do-bar'. Both cmdlets need to authenticate to a service in order to perform their action, and 'do-bar' takes a foo. Today, I can do: new-foo -host localhost -username user -password password -whateverOtherArgs And I can do: do-bar -host localhost -username user -password password -foo myFoo ...

pass username and password to get-credential or run sql query without using invoke-sqlcmd in Powershell

I am trying to connect to a remote sql database and simply run the "select @@servername" query in Powershell. I'm trying to do this without using integrated security. I've been struggling with "get-credential" and "invoke-sqlcmd", only to find (I think), that you can't pass the password from "get-credential" to another Powershell cmdle...

Run Exchange Management Shell cmdlets from Visual Basic/C#/.NET app

Goal: Provide a web service using Visual Basic or C# or .NET that interacts with the Exchange Management Shell, sending it commands to run cmdlets, and return the results as XML. (Note that we could use any lanaguage to write the service, but since it is a Windows Box and we have Visual Studio 2008, it seemed like easiest solution would ...

Join two results in Powershell

I've got two CMDlets that return lists of objects. One returns objects of the type SPSolution, which contains the property Id, the other returns objects of the type SPFeature with a property SolutionId. Now I want to join/merge this data something like this: $f = Get-Feature $s = Get-Solution $result = <JOIN> $f $s <ON> $f.So...

Exchange cmdlets from c#

Hi to all, i need to run exchange cmdlets from a c# console application. i followed with success the guide from http://msdn.microsoft.com/en-us/library/bb332449.aspx but only for the basic command and one parameter. the cmdlets i need to run is: Get-MailboxStatistics -server evs | Select servername, StorageGroupName,databasename,@{e...