< Back
Set-ByteArrayPadding
Post
NAME Set-ByteArrayPadding
SYNOPSIS
Pads an array with a leading byte so that the resulting array is the length specified.
SYNTAX
Set-ByteArrayPadding [[-InputObject] <Byte[]>] [-Length] <Int32> [[-Padding] <Byte>] [-PadEnd] [<CommonParameters>]
Set-ByteArrayPadding [-ReferenceObject] <PSReference> [-Length] <Int32> [[-Padding] <Byte>] [-PadEnd]
[<CommonParameters>]
DESCRIPTION
This cmdlet takes an input array, creates a new array initialized with the padding byte specified, and
then copies the supplied input array to the end of the new array. So if the array @(0x01, 0x02) was supplied with
a padding
byte of 0x03 and a length of 4, the resulting array would be @(0x03, 0x03, 0x01, 0x02).
The original input array is unchanged and the resulting data is a new object returned to the pipeline if used with
InputObject or supplied
via the pipeline. The original array can be modified by use of the ReferenceObject parameter.
PARAMETERS
-InputObject <Byte[]>
The array that needs to be padded.
Required? false
Position? 1
Default value @()
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-ReferenceObject <PSReference>
A reference to the array that needs to be padded. If this parameter is supplied, no output is returned to the
pipeline
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Length <Int32>
The desired length of the resulting array.
Required? true
Position? 2
Default value 0
Accept pipeline input? false
Accept wildcard characters? false
-Padding <Byte>
The byte value used to pad the left hand side of the array. This defaults to 0x00.
Required? false
Position? 4
Default value 0
Accept pipeline input? false
Accept wildcard characters? false
-PadEnd [<SwitchParameter>]
Instead of padding the left side of the array, the right side of the array is padded, so for an input of
@(0x01) and a lenght of 4,
the resulting array would be @(0x01, 0x00, 0x00, 0x00).
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
None or System.Byte[]
NOTES
AUTHOR: Michael Haken
LAST UPDATE: 1/19/2018
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$Arr = @(0x01)
$Arr = $Arr | Set-ByteArrayPadding -Length 4
The resulting array in $Arr is length 4 and its contents are: @(0x00, 0x00, 0x00, 0x01)
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$Arr = @(0x01)
Set-ByteArrayPadding ([ref]$Arr) -Length 2 -Padding 0xFF -PadEnd
The variable $Arr is modified by reference so that the original variable's contents after the cmdlet are @(0x01,
0xFF). Here the array
is padded on the end with the specified 0xFF byte.
RELATED LINKS
SYNOPSIS
Pads an array with a leading byte so that the resulting array is the length specified.
SYNTAX
Set-ByteArrayPadding [[-InputObject] <Byte[]>] [-Length] <Int32> [[-Padding] <Byte>] [-PadEnd] [<CommonParameters>]
Set-ByteArrayPadding [-ReferenceObject] <PSReference> [-Length] <Int32> [[-Padding] <Byte>] [-PadEnd]
[<CommonParameters>]
DESCRIPTION
This cmdlet takes an input array, creates a new array initialized with the padding byte specified, and
then copies the supplied input array to the end of the new array. So if the array @(0x01, 0x02) was supplied with
a padding
byte of 0x03 and a length of 4, the resulting array would be @(0x03, 0x03, 0x01, 0x02).
The original input array is unchanged and the resulting data is a new object returned to the pipeline if used with
InputObject or supplied
via the pipeline. The original array can be modified by use of the ReferenceObject parameter.
PARAMETERS
-InputObject <Byte[]>
The array that needs to be padded.
Required? false
Position? 1
Default value @()
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-ReferenceObject <PSReference>
A reference to the array that needs to be padded. If this parameter is supplied, no output is returned to the
pipeline
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Length <Int32>
The desired length of the resulting array.
Required? true
Position? 2
Default value 0
Accept pipeline input? false
Accept wildcard characters? false
-Padding <Byte>
The byte value used to pad the left hand side of the array. This defaults to 0x00.
Required? false
Position? 4
Default value 0
Accept pipeline input? false
Accept wildcard characters? false
-PadEnd [<SwitchParameter>]
Instead of padding the left side of the array, the right side of the array is padded, so for an input of
@(0x01) and a lenght of 4,
the resulting array would be @(0x01, 0x00, 0x00, 0x00).
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
None or System.Byte[]
NOTES
AUTHOR: Michael Haken
LAST UPDATE: 1/19/2018
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$Arr = @(0x01)
$Arr = $Arr | Set-ByteArrayPadding -Length 4
The resulting array in $Arr is length 4 and its contents are: @(0x00, 0x00, 0x00, 0x01)
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$Arr = @(0x01)
Set-ByteArrayPadding ([ref]$Arr) -Length 2 -Padding 0xFF -PadEnd
The variable $Arr is modified by reference so that the original variable's contents after the cmdlet are @(0x01,
0xFF). Here the array
is padded on the end with the specified 0xFF byte.
RELATED LINKS