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?
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()
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).