A little curiosity I thought I’d share! I wanted to
format dates in PowerShell in a particular way, and wanted to know what the
Get-Date -uFormat %? result is for every letter in the alphabet - lowercase and
capitals (replacing the ? each time with a letter.) So, I wrote this one liner:
$alphabet
= "abcdefghijklmnopqrstuvwxyz"; ""; "PowerShell
Get-Date -uFormat %? Results"; "Date = " + (Get-Date);
""; "%? Result".PadRight(28," ") + "%?
Result"; "~~ ~~~~~~".PadRight(28," ") + "~~
~~~~~~"; $i=0; while ($i -lt 26){ [String]$lcase = $alphabet[$i];
[String]$ucase = $lcase.ToUpper(); $column2 = get-date -uformat %$lcase;
$column4 = get-date -uformat %$ucase; ($lcase.PadRight(3," ")) +
$column2.trim("`n").trim("`t").PadRight(25," ") +
($ucase.PadRight(3," ")) +
$column4.trim("`n").trim("`t"); $i++ }; ""
Okay, it’s not really a proper one liner with all those
semi-colons in, but it does work all from one line …
And here’s the output:
PowerShell
Get-Date -uFormat %? Results
Date
= 02/23/2015 14:35:15
%?
Result %? Result
~~
~~~~~~ ~~ ~~~~~~
a Mon A Monday
b Feb B February
c Mon Feb 23 14:35:15 2015 C 20
d 23 D 02/23/15
e 23 E E
f f F F
g 15 G 2015
h Feb H 14
i i I 02
j 54
J J
k 14 K K
l 02 L L
m 02 M 35
n N N
o o O O
p PM P P
q q Q Q
r 02:35:15 PM R
14:35
s 1424702115.27574 S
15
t T 14:35:15
u 1 U 7
v v V 8
w 1 W 7
x 02/23/15 X 14:35:15
y 15 Y 2015
z z Z +07
Comments
Post a Comment