using System.Management.Automation; using PSTestLib; [Cmdlet(VerbsCommon.Get, "Example")] public class GetExampleCommand : PSCmdletBase { protected override void ProcessRecord() { WriteObject("This is an example output message."); } }
using System.Management.Automation; using PSTestLib; [Cmdlet(VerbsCommon.Get, "Example")] public class GetExampleCommand : PSCmdletBase { [Parameter(Mandatory = true)] public string Path { get; set; } protected override void ProcessRecord() { if (FileExists(Path)) { WriteObject($"File {Path} exists."); } else { WriteObject($"File {Path} does not exist."); } } }In this example, we define a new PowerShell cmdlet named "Get-Example" using the PSCmdletBase class. We add a parameter to the cmdlet named "Path" which is marked as mandatory. In the ProcessRecord() method, we use the FileExists() method from the PSCmdletBase class to check if the file specified by the "Path" parameter exists. We use the WriteObject() method to output a message indicating whether the file exists or not. Overall, PSTestLib is a package library that provides useful tools for creating PowerShell cmdlets and modules. It includes the PSCmdletBase class which simplifies the process of creating cmdlets and provides useful methods and properties for interacting with PowerShell.