https://github.com/yevrag35/pscmdletextensions
A small library of PSCmdlet extension methods including LINQ parameter checking and piped object retrieval.
https://github.com/yevrag35/pscmdletextensions
csharp csharp-library extension-methods linq powershell
Last synced: 6 months ago
JSON representation
A small library of PSCmdlet extension methods including LINQ parameter checking and piped object retrieval.
- Host: GitHub
- URL: https://github.com/yevrag35/pscmdletextensions
- Owner: Yevrag35
- License: gpl-3.0
- Created: 2020-02-22T22:24:26.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-22T19:04:43.000Z (about 2 years ago)
- Last Synced: 2025-08-17T12:49:32.330Z (6 months ago)
- Topics: csharp, csharp-library, extension-methods, linq, powershell
- Language: C#
- Homepage:
- Size: 146 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
README
#  MG.Posh.Extensions
[](https://www.nuget.org/packages/MG.Posh.Extensions) [](https://www.nuget.org/packages/MG.Posh.Extensions)
## BoundParameter Checking with LINQ Expression Example
```csharp
using System;
using System.Management.Automation;
using MG.Posh.Extensions.Bound;
[Cmdlet(VerbsCommon.Get, "Employee", DefaultParameterSetName="ByName")]
public class GetEmployee : PSCmdlet
{
[Parameter(Mandatory=true, Position = 0, ParameterSetName="ByName")]
public string Name { get; set; }
[Parameter(Mandatory=true, Position = 0, ValueFromPipeline=true, ParameterSetName="ByEmployeeId")]
public int Id { get; set; }
protected override void ProcessRecord()
{
if (this.ContainsParameter(x => x.Name))
{
base.WriteVerbose("Gathering employee by name.");
}
// ... and so on.
}
}
```
## PSObject creation with certain class members
```csharp
public struct Employee
{
public int EmployeeId;
public string FirstName;
public string LastName;
public PSObject GetName()
{
return PSOFactory.CreateFromObject(this, e => e.FirstName, e => e.LastName);
}
}
// DISPLAYS
// FirstName LastName
// --------- --------
// Chuck Norris
```