import re
from datetime import datetime


def convert_powershell_date(date_obj_string):
    """
    Converts a string representation of a Date object into datetime

    PowerShell prints this as an msec timestamp

    So this converts to:
    "/Date(1449273876697)/" == datetime.datetime.fromtimestamp(1449273876697/1000.)
    """
    match = re.search(r'^/Date\((\d+)\)/$', date_obj_string)
    if not match:
        raise ValueError('Invalid date object string: {}'.format(date_obj_string))
    return datetime.fromtimestamp(int(match.group(1)) / 1000.)