From b38f2b6cefbd23740ca11fd204bb64abfd2c222a Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Fri, 1 Dec 2023 18:32:43 -0600 Subject: [PATCH] Allow padding of strings by setting a MinLength when converting to bytes --- LANCommander.PowerShell/Cmdlets/ConvertTo-StringBytes.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/LANCommander.PowerShell/Cmdlets/ConvertTo-StringBytes.cs b/LANCommander.PowerShell/Cmdlets/ConvertTo-StringBytes.cs index dced3b9..72cb014 100644 --- a/LANCommander.PowerShell/Cmdlets/ConvertTo-StringBytes.cs +++ b/LANCommander.PowerShell/Cmdlets/ConvertTo-StringBytes.cs @@ -20,6 +20,9 @@ namespace LANCommander.PowerShell.Cmdlets [Parameter] public int MaxLength { get; set; } = 0; + [Parameter] + public int MinLength { get; set; } = 0; + protected override void ProcessRecord() { byte[] output; @@ -27,6 +30,11 @@ namespace LANCommander.PowerShell.Cmdlets if (MaxLength > 0 && Input.Length > MaxLength) Input = Input.Substring(0, MaxLength); + if (MinLength > 0 && MinLength < MaxLength) + Input = Input.PadRight(MinLength, '\0'); + else if (MinLength > 0) + Input = Input.PadRight(MaxLength, '\0'); + if (Utf16 && BigEndian) output = System.Text.Encoding.BigEndianUnicode.GetBytes(Input); else if (Utf16)