Calculate CRC32 in PowerShell

Calculating checksums are perhaps not the first thing you would think of needing to do in PowerShell. But if you ever are in a situation that you need to calculate a checksum using the CRC32 algorithm, I got you covered with this small function.

I can’t take full credit for the code itself, all I did was converting the code from C to PowerShell.


[System.Text.Encoding]::ASCII.GetBytes("PowerShell") | Get-CRC32

This will give you the CRC32 checksum of 2730794414, which is an INT64. If you want to convert it to HEX, you can do the following:


This will give you the HEX value of a2c49dae.

The function takes a byte array as input, which is the reason I had to convert the string in the example above.

Here is the function it self, with another example included:

function Get-CRC32 {
Calculate CRC.
This function calculates the CRC of the input data using the CRC32 algorithm.
Get-CRC32 $data
$data | Get-CRC32
C to PowerShell conversion based on code in
Author: Øyvind Kallstad
Date: 06.02.2017
Version: 1.0
param (
# Array of Bytes to use for CRC calculation
[Parameter(Position = 0, ValueFromPipeline = $true)]
Begin {
function New-CrcTable {
[uint32]$c = $null
$crcTable = New-Object 'System.Uint32[]' 256
for ($n = 0; $n -lt 256; $n++) {
$c = [uint32]$n
for ($k = 0; $k -lt 8; $k++) {
if ($c -band 1) {
$c = (0xEDB88320 -bxor ($c -shr 1))
else {
$c = ($c -shr 1)
$crcTable[$n] = $c
Write-Output $crcTable
function Update-Crc ([uint32]$crc, [byte[]]$buffer, [int]$length) {
[uint32]$c = $crc
if (-not($script:crcTable)) {
$script:crcTable = New-CrcTable
for ($n = 0; $n -lt $length; $n++) {
$c = ($script:crcTable[($c -bxor $buffer[$n]) -band 0xFF]) -bxor ($c -shr 8)
Write-output $c
$dataArray = @()
Process {
foreach ($item in $InputObject) {
$dataArray += $item
End {
$inputLength = $dataArray.Length
Write-Output ((Update-Crc crc 0xffffffffL buffer $dataArray length $inputLength) -bxor 0xffffffffL)
[byte[]]$testCrc = 44,6,119,207
[byte[]]$testData = 73,72,68,82,0,0,0,32,0,0,0,32,1,0,0,0,1
# should be the same
Get-CRC32 $testData

view raw


hosted with ❤ by GitHub


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s