December 27, 2019 at 12:00 am
Comments posted to this topic are about the item The directory creation time
December 27, 2019 at 2:32 pm
nice question and good reminder
---------------------------------------------------------------------------------------
The more you know, the more you know that you dont know
December 30, 2019 at 1:10 pm
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 🙂
December 31, 2019 at 4:36 pm
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 ==.
January 2, 2020 at 10:16 pm
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.
January 2, 2020 at 11:05 pm
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
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply