< Back

Invoke-ByteArrayTrim

Sat Jan 11, 2020 12:34 pm

NAME Invoke-ByteArrayTrim



SYNOPSIS

Trims a byte array to the desired length.





SYNTAX

Invoke-ByteArrayTrim [-InputObject] <Byte[]> -DesiredLength <Int32> [-TrimStart] [<CommonParameters>]





DESCRIPTION

This cmdlet trims a byte array down to the specified size. By default,

bytes are removed from the end of the array unless TrimStart is specified.





PARAMETERS

-InputObject <Byte[]>

The byte array to trim.



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-DesiredLength <Int32>

The new desired length of the array. If the array is equal to or smaller in size

than the desired length, no actions are performed and the array is returned as is.



Required? true

Position? named

Default value 0

Accept pipeline input? false

Accept wildcard characters? false



-TrimStart [<SwitchParameter>]

If specified, bytes are trimmed from the beginning of the array instead of the end.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

System.Byte[]





OUTPUTS

System.Byte[]





NOTES





AUTHOR: Michael Haken

LAST UPDATE: 1/22/2018



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$B = @(0x00, 0x01, 0x02)



$B = $B | Invoke-ByteArrayTrim -DesiredLenth 1



In this example, the byte array $B is trimmed down to a length of 1 and results in an array

containing @(0x00).









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$B = @(0x00, 0x01, 0x02)



$B = $B | Invoke-ByteArrayTrim -DesiredLenth 2 -TrimStart



In this example, the byte array $B is trimmed down to a length of 2 and results in an array

containing @(0x01, 0x02).











RELATED LINKS