The directory creation time

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 717790

    Comments posted to this topic are about the item The directory creation time

  • Shayn Thomas

    SSCertifiable

    Points: 5575

    nice question and good reminder

    ---------------------------------------------------------------------------------------
    The more you know, the more you know that you dont know

  • Ray Herring

    SSCertifiable

    Points: 5444

    This idiosyncrasy of PowerShell has frustrated me from day 1 of PS 2.0

    When the variable is expanded, whether to use double or single quotes, curly braces etc.

    The syntax of a language should not have such subtle differences, otherwise just use English. It has enough ambiguity for anyone 🙂

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 717790

    I agree, Ray. PoSh was supposed to be logical and make more sense than Bash, etc. Instead, there are some silly items like this, and like -eq and -ne rather than respecting = or ==.

  • jkeefe

    SSC Enthusiast

    Points: 139

    Actually, this makes perfect sense to me. The CreationTime is a property of the $directory object. In the quoted string, $directory.CreationTime cannot be determined because the parser doesn't recognize it as a simple data value. To get what you want you should do something like this:

    $directory = Get-Item 'C:\Program Files\Microsoft SQL Server'

    $dTime = $directory.CreationTime

    $message = "SQLDirectory Creation: $dTime"

    This works because $dTime is a simple data value.

  • Jeffrey Williams

    SSC Guru

    Points: 88324

    jkeefe wrote:

    Actually, this makes perfect sense to me. The CreationTime is a property of the $directory object. In the quoted string, $directory.CreationTime cannot be determined because the parser doesn't recognize it as a simple data value. To get what you want you should do something like this:

    $directory = Get-Item 'C:\Program Files\Microsoft SQL Server'

    $dTime = $directory.CreationTime

    $message = "SQLDirectory Creation: $dTime"

    This works because $dTime is a simple data value.

    The problem is that Powershell recognizes $directory and parses its default value and then concatenates the rest of the string.  To force an evaluation of the object property you can do this:

    $message = "SQLDirectory Creation: $($directory.CreationTime)";

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply