#1 30 Nov 2016 20:51

kingtermite
Member
Registered: 28 Oct 2016
Posts: 12

Help doing this "old" version way

I'm writing a script that needs to run one some systems at work that have an older version of Powershell. $PSVersionTable shows it to be version 2.

I'm getting an error with this command:

# Gets last 8 bytes at end of file to check if it is the CRC or not.
# The 'sign' for the CRC present is 4 bytes of 0xFF right before the 4
# bytes of CRC value at the end of the file (e.g. 0xFFFFFFFF<crc32>).
[Byte[]]$tailbytes = Get-Content -path $loFile -Tail 8  -Encoding Byte

Basically, stripping 8 bytes (of binary data) off of a text file (that was put there by another program). It works fine on my machine (PS 3.0), but it chokes on the "-Tail" attribute.

When I check help on both systems, sure enough Tail is not mentioned on the PS 2.0 system as a valid option, but it is on v3.0.

Can anybody suggest an "old" way to do this prior to the -Tail attribute?

Offline

#2 30 Nov 2016 23:10

kingtermite
Member
Registered: 28 Oct 2016
Posts: 12

Re: Help doing this "old" version way

I think I may have found it. Anybody see a problem with this method?

$fpath = "SOwithCRC.xml"
$fs = [IO.File]::OpenWrite($fpath)
$fs.SetLength($fs.Length - 8)
$fs.Close()

Offline

#3 01 Dec 2016 00:00

kingtermite
Member
Registered: 28 Oct 2016
Posts: 12

Re: Help doing this "old" version way

OK...the first bit was reading the bytes, and the second is stripping it off. But that's easy enough to fix. There is a ReadByte() method in the FileStream class.

I do still need to strip it and a quick test showed this to work (and in PS 2.0).

Offline

Board footer

Powered by FluxBB