I need a PowerShell script that can access a file’s properties and discover the LastWriteTime property and compare it with the current date and return the date difference.
I have something like this…
$writedate = Get-ItemProperty -Path $source -Name LastWriteTime
…but I can not cast the LastWriteTime to a “DateTime” datatype. It says, “Cannot convert “@{LastWriteTime=…date…}” to “System.DateTime”.
Try the following.
This is part of the item property weirdness. When you run Get-ItemProperty it does not return the value but instead the property. You have to use one more level of indirection to get to the value.