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.

Example

[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:

[System.Convert]::ToString(2730794414,16)

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:

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s