![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Need help with .CreationTime Why is it that when I uncomment the "start-sleep" line in the below script, I get the correct value returned for my creationtime--but when I comment it out, I do not get the correct creationtime for the file? This is driving me nuts! If this seems to work for you the first time you run it, wait a minute and run it again. "test1" > c:\test.txt (gci c:\test.txt).creationtime del c:\test.txt ### You'll get an error when the command below runs b/c the file doesn't exist. (gci c:\test.txt).creationtime #start-sleep 30 new-item -path c:\test.txt -type "file" (gci c:\test.txt).creationtime -- BatchMan |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Need help with .CreationTime Hello BatchMan ;-) I have tested your script and it seems there's a cache somewhere. In fact my tests seems to reveal that the creationtime is not refreshed in real time. When I do that 10 times in 30 seconds : "test1" > c:\test.txt (gci c:\test.txt).creationtime del c:\test.txt the creationTime is not refreshed and keep the value of the first execution time. It is perhaps linked to the framework .net ? I don't have any idea. Perhaps it's a bug. Arnaud PS: you can submit your bug to the MS connect program. I was impressed when I saw the list of bugs submitted... "BatchMan" wrote: Quote: > Why is it that when I uncomment the "start-sleep" line in the below script, I > get the correct value returned for my creationtime--but when I comment it > out, I do not get the correct creationtime for the file? This is driving me > nuts! If this seems to work for you the first time you run it, wait a minute > and run it again. > > "test1" > c:\test.txt > (gci c:\test.txt).creationtime > del c:\test.txt > ### You'll get an error when the command below runs b/c the file doesn't > exist. > (gci c:\test.txt).creationtime > #start-sleep 30 > new-item -path c:\test.txt -type "file" > (gci c:\test.txt).creationtime > > -- > BatchMan |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Need help with .CreationTime Thanks Arnaud. On my machine, a sleep time of 15 seconds works, but 14 seconds does not. I didn't know if that would be true for everyone else so I just changed it to 30. This isn't the first time inside of a week that I've run into a show stopping problem converting my existing batch programs to PowerShell (anyone know how to get a .weekofyear property from a datetime value?). I *really* want to fall madly in love with PS but I don't think she feels the same way.... thanks again, -- BatchMan "A. Petitjean" wrote: Quote: > Hello BatchMan ;-) > > I have tested your script and it seems there's a cache somewhere. In fact my > tests seems to reveal that the creationtime is not refreshed in real time. > > When I do that 10 times in 30 seconds : > "test1" > c:\test.txt > (gci c:\test.txt).creationtime > del c:\test.txt > > the creationTime is not refreshed and keep the value of the first execution > time. > > It is perhaps linked to the framework .net ? I don't have any idea. Perhaps > it's a bug. > > Arnaud > PS: you can submit your bug to the MS connect program. I was impressed when > I saw the list of bugs submitted... > > "BatchMan" wrote: > Quote: > > Why is it that when I uncomment the "start-sleep" line in the below script, I > > get the correct value returned for my creationtime--but when I comment it > > out, I do not get the correct creationtime for the file? This is driving me > > nuts! If this seems to work for you the first time you run it, wait a minute > > and run it again. > > > > "test1" > c:\test.txt > > (gci c:\test.txt).creationtime > > del c:\test.txt > > ### You'll get an error when the command below runs b/c the file doesn't > > exist. > > (gci c:\test.txt).creationtime > > #start-sleep 30 > > new-item -path c:\test.txt -type "file" > > (gci c:\test.txt).creationtime > > > > -- > > BatchMan |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Need help with .CreationTime No problem Batchman ;-) You know, you're welcome to post in the french powershell's forum here http://powershell-scripting.com/inde...oard&Itemid=76 It will be easier for me to understand your problem. Cheers, Arnaud "BatchMan" wrote: Quote: > Thanks Arnaud. On my machine, a sleep time of 15 seconds works, but 14 > seconds does not. I didn't know if that would be true for everyone else so I > just changed it to 30. > > This isn't the first time inside of a week that I've run into a show > stopping problem converting my existing batch programs to PowerShell (anyone > know how to get a .weekofyear property from a datetime value?). I *really* > want to fall madly in love with PS but I don't think she feels the same > way.... > > thanks again, > > > -- > BatchMan > > > "A. Petitjean" wrote: > Quote: > > Hello BatchMan ;-) > > > > I have tested your script and it seems there's a cache somewhere. In fact my > > tests seems to reveal that the creationtime is not refreshed in real time. > > > > When I do that 10 times in 30 seconds : > > "test1" > c:\test.txt > > (gci c:\test.txt).creationtime > > del c:\test.txt > > > > the creationTime is not refreshed and keep the value of the first execution > > time. > > > > It is perhaps linked to the framework .net ? I don't have any idea. Perhaps > > it's a bug. > > > > Arnaud > > PS: you can submit your bug to the MS connect program. I was impressed when > > I saw the list of bugs submitted... > > > > "BatchMan" wrote: > > Quote: > > > Why is it that when I uncomment the "start-sleep" line in the below script, I > > > get the correct value returned for my creationtime--but when I comment it > > > out, I do not get the correct creationtime for the file? This is driving me > > > nuts! If this seems to work for you the first time you run it, wait a minute > > > and run it again. > > > > > > "test1" > c:\test.txt > > > (gci c:\test.txt).creationtime > > > del c:\test.txt > > > ### You'll get an error when the command below runs b/c the file doesn't > > > exist. > > > (gci c:\test.txt).creationtime > > > #start-sleep 30 > > > new-item -path c:\test.txt -type "file" > > > (gci c:\test.txt).creationtime > > > > > > -- > > > BatchMan |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Need help with .CreationTime I'm a .Net apprentice, so there could very well be a better way. You need to load Microsoft.VisualBasic.dll from your $profile and create a function there also, so you can always access it. This goes in your $profile: [void][System.Reflection.Assembly]::Load('Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') function Get-WeekOfYear ([dateTime]$date = (get-date)) { [Microsoft.VisualBasic.DateAndTime]::datePart('ww',($date),1) } New-Alias woy Get-WeekOfYear -opt ReadOnly, AllScope -sco Global .... you can also add a scriptProperty to the [DateTime] type. Put the following in a ps1xml file, let's say ExtendedTypes.ps1xml <Types> <Type> <Name>System.DateTime</Name> <Members> <ScriptProperty> <Name>WeekOfYear</Name> <GetScriptBlock> [Microsoft.VisualBasic.DateAndTime]::datePart('ww',($this),1) </GetScriptBlock> </ScriptProperty> </Members> </Type> </Types> ....and from your $profile extend the type like this: Update-TypeData <yourDir>\ExtendedTypes.ps1xml Then you'll be able to: woy '7.4.1776' $weekOfYear = (get-date).weekOfYear $weekOfYear -- Kiron |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Need help with .CreationTime A. Petitjean wrote: Quote: > PS: you can submit your bug to the MS connect program. I was impressed when > I saw the list of bugs submitted... ![]() -- Hal Rottenberg blog: http://halr9000.com powershell category: http://halr9000.com/article/category...ng/powershell/ |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Need help with .CreationTime Here's another way. Use Get-Date's Unix format parameter '-uFormat' and the 'week of year' value '%V' get-date -uFormat %V function Get-WeekOfYear ([dateTime]$date = (get-date)) { get-date $date -uFormat %V } New-Alias woy Get-WeekOfYear -opt ReadOnly, AllScope -sco Global .... you can add the scriptProperty to the [DateTime] type. -- ExtendedTypes.ps1xml -- <Types> <Type> <Name>System.DateTime</Name> <Members> <ScriptProperty> <Name>WeekOfYear</Name> <GetScriptBlock> get-date $this -uFormat %V </GetScriptBlock> </ScriptProperty> </Members> </Type> </Types> -- ExtendedTypes.ps1xml -- ....and extend the type from your $profile. Update-TypeData ExtendedTypes.ps1xml # call the function woy 35 woy '7.4.1776' 27 # read the property (get-date).weekOfYear 35 ([dateTime]'7.4.1776').weekOfYear 27 -- Kiron |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Need help with .CreationTime "BatchMan" <BatchMan@xxxxxx> wrote in message news:29B13538-5990-40CF-80FC-E949C21F45E4@xxxxxx Quote: > Thanks Arnaud. On my machine, a sleep time of 15 seconds works, but 14 > seconds does not. I didn't know if that would be true for everyone else > so I > just changed it to 30. > > This isn't the first time inside of a week that I've run into a show > stopping problem converting my existing batch programs to PowerShell > (anyone > know how to get a .weekofyear property from a datetime value?). I > *really* > want to fall madly in love with PS but I don't think she feels the same > way.... PowerShell. See Raymond Chen's blog on file system tunnelling which might at least explain why you get a "fake" creation time: http://blogs.msdn.com/oldnewthing/ar...15/439261.aspx With that said, and now that Kiron has also showed you how to easily obtain the week of year property, you should be packing for your honey moon! :-) Jacques |
My System Specs![]() |