After searching the interwebs, I've managed to create a C# class to get a FileTimeUTC Hex String.
public class HexHelper
{
public static string GetUTCFileTimeAsHexString()
{
string sHEX = "";
long ftLong = DateTime.Now.ToFileTimeUtc();
int ftHigh = (int)(ftLong >> 32);
int ftLow = (int)ftLong;
sHEX = ftHigh.ToString("X") + ":" + ftLow.ToString("X");
return sHEX;
}
}
For PowerShell I've tried using this same code:
$HH = @"
public class HexHelper
{
public static string GetUTCFileTimeAsHexString()
{
string sHEX = "";
long ftLong = DateTime.Now.ToFileTimeUtc();
int ftHigh = (int)(ftLong >> 32);
int ftLow = (int)ftLong;
sHEX = ftHigh.ToString("X") + ":" + ftLow.ToString("X");
return sHEX;
}
}
"@;
Add-Type -TypeDefinition $HH;
$HexString = [HexHelper]::GetUTCFileTimeAsHexString();
$HexString;
The problem is I get a few error messages:
The name 'DateTime' does not exist in the current context
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. Compilation errors occurred.
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
I don't know how to get this C# code valid for PowerShell and would like a working solution. I don't know why PowerShell can't recognize the DateTime class in my C# snippet.
Turns out you need to include the using directive. In this case, "using System;"