I have written 2 cmdlets, for converting between GUIDs and Oracle's Guid equivalent, the strings it displays for RAW columns used to store GUIDs. The first, Convert-GuidToRaw, accepts a GUID string param and outputs a raw string:
var raw = GuidConverter.Core.GuidConverter.ToRaw(Input);
WriteObject(raw);
Where raw has type string. When I run this cmdlet, I get a plain and simple string output:
PS D:\SANRAL\NRA2> New-Guid | Convert-GuidToRaw
DD8386EE09231A43B7731880CCAD6B87
PS D:\SANRAL\NRA2>
My other cmdlet, Convert-RawToGuid, accepts a RAW string param representing a GUID and outputs a raw GUID:
var guid = GuidConverter.Core.GuidConverter.FromRaw(Input);
WriteObject(guid);
Where guid has type Guid. When I run this cmdlet, I get output formatted like a table:
PS D:\SANRAL\NRA2> Convert-RawToGuid DD8386EE09231A43B7731880CCAD6B87
Guid
----
ee8683dd-2309-431a-b773-1880ccad6b87
PS D:\SANRAL\NRA2>
In both cases I output a single object, not a list, and in both cases the object is easily represented by a simple string. Why do I get tabular output when I return a Guid type?
It may be worth noting that the Convert-GuidToRaw cmdlet, with its plain, un-formatted, string output, doesn't seem to properly write to the pipeline. Both cmdlets take one parameter, from the pipeline. I would expect this cmdlet pipeline below to output a GUID, when instead the last cmdlet in the pipeline is till looking for input:
PS C:\WINDOWS\system32> New-Guid | Convert-GuidToRaw | Convert-RawToGuid
cmdlet Convert-RawToGuid at command pipeline position 3
Supply values for the following parameters:
Input:
Why is Convert-RawToGuid not getting a "pipelined" string from Convert-GuidToRaw? Swapping the order of the pipeline as below, causes the expected behaviour:
PS C:\WINDOWS\system32> Convert-RawToGuid F3BD9411DE8E4F4BBCACECFCED6D305D | Convert-GuidToRaw
F3BD9411DE8E4F4BBCACECFCED6D305D
PS C:\WINDOWS\system32>
The Convert-RawToGuid cmdlet looks like this:
[Cmdlet(VerbsData.Convert, "RawToGuid")]
public class ConvertRawToGuidCommand : System.Management.Automation.Cmdlet
{
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)]
public string Input { get; set; }
protected override void ProcessRecord()
{
if (string.IsNullOrEmpty(Input) || Input.Length != 32)
{
throw new ArgumentException("Input must be a 32 character hex string");
}
var guid = GuidConverter.Core.GuidConverter.FromRaw(Input);
WriteObject(guid);
}
}
The Convert-GuidToRaw cmdlet looks like this:
[Cmdlet(VerbsData.Convert, "GuidToRaw")]
public class ConvertGuidToRawCommand : System.Management.Automation.Cmdlet
{
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)]
public Guid Input { get; set; }
protected override void ProcessRecord()
{
var raw = GuidConverter.Core.GuidConverter.ToRaw(Input);
WriteObject(raw);
}
}
Microsoft.PowerShell.5.1.ReferenceAssembliesand then just pasting your code into two new class files (except for the serialisation format - usingInput.ToString()andnew Guid(this.Input)to convert values). Then, in PowerShellImport-Module ".\MyCmdlet.dll"; New-Guid | Convert-GuidToRaw | Convert-RawToGuidand it just works :-S. Could you see if your project is any different to my repro, and maybe try my steps yourself?Input.ToString()and newGuid(this.Input)? Nowhere can the input string be converted straight to aGuid- it must be parsed.