|
Converting date time format to string format See Part 1 of this code
==================================================================
# both are in date time format
$created = get-date -year 2007 -month 12 -day 1
$created1 = get-date
# converted to string format
$a = $created.tostring("f")
$aa = $created1.tostring("f")
# assign a variable to hold all values, separated by comma
$grouparray = ($a,$aa)
$group = $grouparray | foreach
{([regex]'([A-za-z]+\s[0-9]+,\s[0-9]+)').match($_).value}
$group | group -noelement | select name, count | sort -property name
==================================================================
Result i got is :
Name
Count
---- -----
December 01, 2007
1
December 18, 2007
1
==================================================================
See Part 2 of this code
==================================================================
# in date time format
$created = get-date -year 2007 -month 12 -day 1
$files = get-childitem d:\backup | ? {!$_.PSIsContainer -and
($_.lastwriteTime -ge $created)} | select lastwriteTime | foreach
{$_.lastwriteTime}
# still in date time format
$files
Results show below :
==================================================================
Tuesday, December 04, 2007 12:34:55 PM
Tuesday, December 04, 2007 12:09:04 PM
Monday, December 10, 2007 1:57:47 PM
Sunday, December 09, 2007 5:31:06 PM
Tuesday, December 11, 2007 1:42:29 PM
Tuesday, December 04, 2007 3:56:21 PM
Wednesday, December 05, 2007 10:13:43 AM
Tuesday, December 04, 2007 11:57:49 AM
Tuesday, December 04, 2007 10:07:32 AM
Friday, December 07, 2007 7:44:57 PM
Monday, December 10, 2007 12:21:33 PM
Tuesday, December 11, 2007 1:29:50 PM
Monday, December 10, 2007 2:21:37 PM
==================================================================
Here are the questions :
a) In part 2 of the code, i want to convert $files into a string format. I
try to do this :
$abc = $files.tostring("f")
This does not work. Error Cannot find an overload for "ToString" and the
argument count: "1". I think the tostring method expects a "1" argument
instead of multiple lines arguement. How do i convert $files into similar
Part 1 of the code as in below :
# assign a variable to hold all values, separated by comma
# this is a string format i want.
$grouparray = ($a,$aa) |