Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: General » microsoft.public.windows.powershell
Thread: assigning random creation dates to files

HTVi
TV Discussion Newsgroups

assigning random creation dates to files
sardinian_guy <guest[ at ]unknown-email.com> 12/30/2008 3:29:49 PM
Hallo guys and happy new year to everybody. :D Sometimes to make tests I need to assign different creation dates between a specific range to my files. I'm looking for a way to do it with powershell. I found this article 'Generate Random Dates in PowerShell « saadware' (http://blog.saadware.com/2008/06/12/generate-random-dates-in-powershell/) but i don't know how to apply this code to each file within a folder. Thanks in advance. -- sardinian_guy
Re: assigning random creation dates to files
"Oisin (x0n) Grehan [MVP]" <oising[ at ]gmail.com> 12/30/2008 4:14:12 PM
On Dec 30, 10:29 am, sardinian_guy <gu...[ at ]unknown-email.com> wrote:
[Quoted Text]
> Hallo guys and happy new year to everybody. :D
> Sometimes to make tests I need to assign different creation dates
> between a specific range to my files. I'm looking for a way to do it
> with powershell.
>
> I found this article
> 'Generate Random Dates in PowerShell « saadware'
> (http://blog.saadware.com/2008/06/12/generate-random-dates-in-powershell/)
>
> but i don't know how to apply this code to each file within a folder.
> Thanks in advance.
>
> --
> sardinian_guy

Hi,

If you install the PowerShell Community Extensions from
http://www.codeplex.com/powershellcx - there is a Cmdlet called Set-
FileTime which will let you do this:

ps> dir c:\files\ -rec -inc *.txt | set-filetime -created (get-
randomdate)

(get-randomdate is your function)

- Oisin
Re: assigning random creation dates to files
sardinian_guy <guest[ at ]unknown-email.com> 12/30/2008 7:09:53 PM
'Oisin (x0n) Grehan [MVP Wrote: > ;924303']On Dec 30, 10:29*am, sardinian_guy <gu...[ at ]xxxxxx-email.com> > wrote:> > > > > > Hallo guys and happy new year to everybody. :D > > > Sometimes to make tests I need to assign different creation dates > > > between a specific range to my files. I'm looking for a way to do it > > > with powershell. > > > > > > I found this article > > > 'Generate Random Dates in PowerShell « saadware' > > > ('Generate Random Dates in PowerShell « saadware' > > (http://blog.saadware.com/2008/06/12/generate-random-dates-in-powershell/)) > > > > > > but i don't know how to apply this code to each file within a folder. > > > Thanks in advance. > > > > > > -- > > > sardinian_guy > > Hi, > > If you install the PowerShell Community Extensions from > 'PowerShell Community Extensions - Home' > (http://www.codeplex.com/powershellcx) - there is a Cmdlet called Set- > FileTime which will let you do this: > > ps> dir c:\files\ -rec -inc *.txt | set-filetime -created (get- > randomdate) > > (get-randomdate is your function) > > - Oisin Thank you very much for your answer. I'll try these extensions. :D Is there however a way to solve it without installing anything? -- sardinian_guy
Re: assigning random creation dates to files
"Vadims Podans" <vpodans> 12/30/2008 7:22:36 PM
The general behaviour is:

[vPodans] $a = Get-Item saferlog.txt
[vPodans] $a.CreationTime

pirmdiena, 2008. gada 29. decembri 13:07:27


[vPodans] function Get-RandomDate {
[Quoted Text]
>> [DateTime]$theMin = "1/1/2008"
>> [DateTime]$theMax = [DateTime]::Now
>> $theRandomGen = new-object random
>> $theRandomTicks = [Convert]::ToInt64( ($theMax.ticks * 1.0 -
>> $theMin.Ticks * 1.0 ) * $theRandomGen.NextDouble() + $th
eMin.Ticks * 1.0 )
>> new-object DateTime($theRandomTicks)
>> }
>>
[vPodans] $a.CreationTime = Get-RandomDate
[vPodans] $a.CreationTime

tresdiena, 2008. gada 2. julija 2:18:02


[vPodans] $a.CreationTime = Get-RandomDate
[vPodans] $a.CreationTime

piektdiena, 2008. gada 30. maija 21:59:08


[vPodans]

you just create function (from
http://blog.saadware.com/2008/06/12/generate-random-dates-in-powershell/),
and using it you just assign a new value for file CreationTime property.

Enjoy!
--
WBR, Vadims Podans
PowerShell blog - www.sysadmins.lv

"sardinian_guy" <guest[ at ]unknown-email.com> rakstīja ziņojumā
"news:3488d5755da95b184cdd9ae68ae14910[ at ]nntp-gateway.com"...
>
> Hallo guys and happy new year to everybody. :D
> Sometimes to make tests I need to assign different creation dates
> between a specific range to my files. I'm looking for a way to do it
> with powershell.
>
> I found this article
> 'Generate Random Dates in PowerShell ╚ saadware'
> (http://blog.saadware.com/2008/06/12/generate-random-dates-in-powershell/)
>
> but i don't know how to apply this code to each file within a folder.
> Thanks in advance.
>
>
> --
> sardinian_guy

Re: assigning random creation dates to files
Matthias Tacke <Matthias[ at ]Tacke.de> 12/30/2008 9:30:50 PM
sardinian_guy wrote:
[Quoted Text]
> Thank you very much for your answer. I'll try these extensions. :D
> Is there however a way to solve it without installing anything?
>
>
Hi,

in the comments of this blog entry you will find a sample dealing with
Dotnet [System.IO.File]::SetCreationTime(... which may help:
<http://blogs.msdn.com/powershell/archive/2006/11/23/processing-eml-files-with-select-string-and-setcreationtime.aspx>

But I may be wrong since I'm quite new to PoSh.

HTH
Matthias
Re: assigning random creation dates to files
sardinian_guy <guest[ at ]unknown-email.com> 12/30/2008 10:52:18 PM
Vadims Podans;924520 Wrote: > The general behaviour is: > > [vPodans] $a = Get-Item saferlog.txt > [vPodans] $a.CreationTime > > pirmdiena, 2008. gada 29. decembri 13:07:27 > > > [vPodans] function Get-RandomDate {> > > > > > > > > > > >> [DateTime]$theMin = "1/1/2008" > > > >> [DateTime]$theMax = [DateTime]::Now > > > >> $theRandomGen = new-object random > > > >> $theRandomTicks = [Convert]::ToInt64( ($theMax.ticks * 1.0 - > > > >> $theMin.Ticks * 1.0 ) * $theRandomGen.NextDouble() + $th > > > > > > eMin.Ticks * 1.0 )[vPodans] $a.CreationTime = Get-RandomDate > [vPodans] $a.CreationTime > > tresdiena, 2008. gada 2. julija 2:18:02 > > > [vPodans] $a.CreationTime = Get-RandomDate > [vPodans] $a.CreationTime > > piektdiena, 2008. gada 30. maija 21:59:08 > > > [vPodans] > > you just create function (from > 'Generate Random Dates in PowerShell « saadware' > (http://blog.saadware.com/2008/06/12/generate-random-dates-in-powershell/)), > and using it you just assign a new value for file CreationTime > property. > > Enjoy! > -- > WBR, Vadims Podans > PowerShell blog - 'www.sysadmins.lv' (http://www.sysadmins.lv) > > "sardinian_guy" <guest[ at ]xxxxxx-email.com> rakstÄ«ja ziņojumā > "news:3488d5755da95b184cdd9ae68ae14910[ at ]xxxxxx-gateway.com"...> > > > > > > > > Hallo guys and happy new year to everybody. :D > > > Sometimes to make tests I need to assign different creation dates > > > between a specific range to my files. I'm looking for a way to do it > > > with powershell. > > > > > > I found this article > > > 'Generate Random Dates in PowerShell ╚ saadware' > > > ('Generate Random Dates in PowerShell « saadware' > > (http://blog.saadware.com/2008/06/12/generate-random-dates-in-powershell/)) > > > > > > but i don't know how to apply this code to each file within a folder. > > > Thanks in advance. > > > > > > > > > -- > > > sardinian_guy > > Thank Vadims for your precious help. :) This code gci | % {$(get-item $_).creationtime = get-randomdate } works. However I made some proof and the dates don't seem so random. If I have few files, the same date occurs for several files. Is it the right behaviour or is it possible to have something more "randomly"? Thanks again -- sardinian_guy

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen