background preloader

Visual C# Developer Center

Visual C# Developer Center

Adding Parameters that Process Command-Line Input The following sections are in this topic: Defining the Cmdlet Class [Cmdlet(VerbsCommon.Get, "proc")] public class GetProcCommand: Cmdlet Declaring Parameters A cmdlet parameter enables the user to provide input to the cmdlet. In the following example, Get-Proc and Get-Member are the names of pipelined cmdlets, and MemberType is a parameter for the Get-Member cmdlet. PS> get-proc | get-member -membertype property To declare parameters for a cmdlet, you must first define the properties that represent the parameters. Here's the parameter declaration for the Name parameter of the Get-Proc cmdlet. /// <summary>/// Specify the cmdlet Name parameter./// </summary> [Parameter(Position = 0)] [ValidateNotNullOrEmpty] public string[] Name { get { return processNames; } set { processNames = value; } } private string[] processNames; #endregion Parameters This cmdlet uses an array of strings for the Name parameter. Things to Remember About Parameter Definitions Declaring Parameters as Positional or Named

Cours Visual Basic Introduction :Visual Basic, un langage (presque) objet Foin de fausse modestie, ce cours poursuit un double objectif : constituer un vade-mecum de départ pour le langage Visual Basic, dans sa version 5 (mais cela vaut tout aussi bien pour la version 6). présenter certains des concepts fondamentaux de la programmation objet Visual Basic étant, comme tout langage moderne, richissime en fonctionnalités, il va de soi que les quelques pages qui suivent ne remplaceront ni une consultation intelligente de l’aide du logiciel, ni le recours à des ouvrages de référence d’une toute autre ampleur (mais d’un tout autre prix. Ajoutons que ce cours serait vide de sens sans les exercices – et les corrigés – qui l’accompagnent. Merci de votre attention, vous pouvez reprendre votre sieste. 1. En quoi un langage objet diffère-t-il d’un langage normal ? Donc, c’est un premier point, on peut tout à fait programmer dans un langage objet comme on programmerait du Fortran, du Cobol ou du C. 1.1 Les Objets 2.

How to write and read a color in C# Transforming a color in hexa representation using following function: private string WriteHexString(byte aobjColR, byte aobjColG, byte aobjColB){string strRet;byte[] btR = {aobjColR};string strR = ToHexString(btR);strRet = strR; byte[] btG = {this.colorDialog1.Color.G};string strG = ToHexString(btG);strRet += strG; byte[] btB = {this.colorDialog1.Color.B};string strB = ToHexString(btB);strRet += strB; return strRet;}//WriteHexString This function transform a Color (defined as Color.R, Color.G, Color.B) in hexa representation (as string) and use following helper functions: private static string ToHexString(byte[] bytes) {char[] chars = new char[bytes.Length * 2];for (int i = 0; i < bytes.Length; i++) {int b = bytes[i];chars[i * 2] = hexDigits[b >> 4];chars[i * 2 + 1] = hexDigits[b & 0xF];}return new string(chars);}//ToHexString static char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7','8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; and helper function: The complete code is in zip file.

Examples of Host Application Code In This Section This section includes the following topics. This example shows how to write a host application that invokes a command synchronously on the local computer. This example shows how to add cmdlets and their parameters to the command pipeline of a host application. After the command pipeline is complete, the host application invokes the pipeline synchronously on the local computer. This example shows how to add a custom host to a host application. This section includes examples that show how to invoke a pipeline synchronously or asynchronously. This section includes examples that show the different ways you can implement a custom host classes, including their related interfaces for supporting prompts for multiple choices and supporting interactive sessions. See Also

Background Jobs Cmdlets can perform their action internally or as a Windows PowerShell background job. When a cmdlet runs as a background job, the work is done asynchronously in its own thread separate from the pipeline thread that the cmdlet is using. From the user perspective, when a cmdlet runs as a background job, the command prompt returns immediately even if the job takes an extended amount of time to complete, and the user can continue without interruption while the job runs. Background Jobs, Child Jobs, and the Job Repository The job object that is returned by the cmdlets that support background jobs defines the job. (The Start-Job cmdlet also returns a job object.) For more information about how background jobs are handled at the command line, see the following: Writing a Cmdlet That Runs as a Background Job To write a cmdlet that can be run as a background job, you must complete the following tasks: Background Job–Related APIs Derives custom job objects. Defines the state of the background job.

Get-CommandPlugin - Windows PowerShell Blog One of the nifty new CTP3 features is command and parameter meta data on functions. In V1, you had to parse a function yourself to extract the parameters. In CTP2, you could use the tokenizer API to parse the function, but extracting parameters this was is error prone. In CTP3, and in V2, you can actually get a dictionary of parameters on the FunctionInfo object. Check it out: Get-Command -type Function | Foreach-Object { $_.Parameters } This opens up a lot of possibilities. One example of how you might want to use this is making a central script that runs all of your diagnostic scripts. Suppose I had several functions that worked against a remote machine: Get-InformationAboutProcessor -computer Get-InformationAboutFreeDiskSpace -computer Get-InformationAboutLocalUsers -computer etc etc etc function Get-Information($computer) { $myInvocation.MyCommand | Get-CommandPlugin -preposition About -parameter Computer | Foreach-Object { & $_ @psBoundParameters } } Synopsis: Detailed Description:

Merry Christmas From PowerShell: The CodeDownloader Module - Windows PowerShell Blog Twas the night before Christmas, and all through the net PowerShell lovers were wondering exactly what they might get Their readers were ready, their minds were aware That more joy of CTP3 would soon be there A cmdlet, a function? What has the PowerShell team done? How about a whole module, to share scripts with everyone? Some pluggable functions, to get code to share Scripts from Write-CommandBlogPost, from PoshCode, from Everywhere And what on the morning of Christmas did they see? But eight advanced functions, to get code from you or me. To rhyme more would be wrong, so I'll just explain. Get the Get-MarkupTag, Resolve-ShortcutFile, and Get-CommandPlugin from the earlier blog posts Download the zip file. Add some of the recent blog posts to your favorites, or some scripts from poshcode, and try using Import-ModuleFromWeb to import some scripts from the web into a module. Import-ModuleFromWeb Detailed Description: Takes a base directory containing directories full of links to post.

Adding Custom Cmdlet Help for Providers - Windows PowerShell Blog A new feature of Windows PowerShell 2.0 lets you write custom cmdlet help for Windows PowerShell providers. This blog explains how to do it. (The topic will also be covered in excruciating detail in MSDN, but we don't want you to wait.) What's a Provider? A Windows PowerShell provider is a C# program that exposes a data store to Windows PowerShell through a Windows PowerShell drive (PSDrive). For more information about designing a Windows PowerShell provider, see How to Create a Windows PowerShell Provider ( If you're a provider author (or the lucky writer), this feature is for you! Custom cmdlets? No, custom help topics for the provider cmdlets that your provider supports. A custom cmdlet help topic explains how the provider cmdlet works in your provider. How do users get custom cmdlet help? C:\PS> cd wsman:\localhost\ClientCertificate PS WSMAN:\localhost\ ClientCertificate> get-help new-item New-Item Creates a new item. What problem does this feature solve?

Improving Parameter Set Design - Windows PowerShell Blog Designing useable cmdlets is part engineering and part art. It’s not an easy task to define the conceptual boundaries of a cmdlet (where does one cmdlet end and the next begin) or to provide great feature control without inundating the user with parameters. However, you can improve the usability of your cmdlets by avoiding two common parameter set design flaws. A parameter set with no mandatory parameters in a cmdlet that requires parameters Mandatory parameters with position numbers that are higher than the position numbers of optional parameters Parameter sets with no mandatory parameters Some cmdlets, like Get-Process, can be run without any parameters, so you'd expect them to have at least one parameter set with no mandatory parameters. But look at the syntax of Get-WmiObject. But it's worse. Unless you can run the cmdlet without parameters, be sure that there is at least one mandatory parameter in each parameter set. Mandatory parameters with high position numbers

Designing Cmdlets That Have Lots of Parameters - Windows PowerShell Blog We often get the question of what to do about a cmdlet that has lots of parameters. Do you break it up into multiple commands or just have a single cmdlet with lots of parameters. Here is the way I think about it: If you have to enter 100 things to get a job done, it doesn’t really matter whether you enter those 100 things via 1 cmdlet with 100 parameters or 10 cmdlets with 10 parameters each. Let me be quick to point out the trick – that is all about if you have to enter 100 things to do something. PS> Get-Help New-PSSession -Parameter SessionOption -SessionOption <PSSessionOption> Sets advanced options for the session. The default values for the options are determined by the value of the $PSSe ssionOption preference variable, if it is set. For a description of the session options, including the default values, see New-PSSessionOption. Required? So the way you get an object to pass to –SessionOption is by calling the New-PSSessionOption cmdlet. Enjoy!

Related: