-
Notifications
You must be signed in to change notification settings - Fork 33
/
powershell_blog.xml
2712 lines (2712 loc) · 568 KB
/
powershell_blog.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Windows PowerShell Blog</title><link>http://blogs.msdn.com/b/powershell/</link><description>Automating the world one-liner at a time...</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>WMI cheat sheet for PS users</title><link>http://blogs.msdn.com/b/powershell/archive/2012/10/28/wmi-cheat-sheet-for-ps-users.aspx</link><pubDate>Sun, 28 Oct 2012 21:10:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10363470</guid><dc:creator>PowerShell Team</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/powershell/rsscomments.aspx?WeblogPostID=10363470</wfw:commentRss><comments>http://blogs.msdn.com/b/powershell/archive/2012/10/28/wmi-cheat-sheet-for-ps-users.aspx#comments</comments><description><p>Hi,</p>
<p>We got multiple requests to publish the cheat sheet for CIM Cmdlets that was distributed in Tech Ed NA&nbsp;this year. Responding to popular demand, this document is attached as PDF . This is a great resource put together by WMI team for people who want to get started with CIM cmdlets.</p>
<p>Standard disclaimer :-). Cheat sheet is just for a quick start to get people started&nbsp;- real documentation is here <a href="http://technet.microsoft.com/en-us/library/jj553783.aspx">http://technet.microsoft.com/en-us/library/jj553783.aspx</a>.</p>
<p>&nbsp;</p>
<p>Thanks</p>
<p>Osama Sajid</p>
<p>Program Manager</p>
<p>&nbsp;</p>
<p>&nbsp;</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10363470" width="1" height="1"></description><enclosure url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-36-34-70/WMI-CheatSheet-for-PS.pdf" length="289863" type="application/pdf" /><category domain="http://blogs.msdn.com/b/powershell/archive/tags/WMI/">WMI</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/CIM/">CIM</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/CimCmdlets/">CimCmdlets</category></item><item><title>Joining Multiple Tables, Grouping and Evaluating Totals</title><link>http://blogs.msdn.com/b/powershell/archive/2012/10/04/joining-multiple-tables-grouping-and-evaluating-totals.aspx</link><pubDate>Thu, 04 Oct 2012 00:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10355722</guid><dc:creator>PowerShell Team</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/powershell/rsscomments.aspx?WeblogPostID=10355722</wfw:commentRss><comments>http://blogs.msdn.com/b/powershell/archive/2012/10/04/joining-multiple-tables-grouping-and-evaluating-totals.aspx#comments</comments><description><div class="WordSection1">
<p class="MsoNormal"><b>Joining Multiple Tables, Grouping And Evaluating Totals</b></p>
<p class="MsoNormal">This is a continuation to the <a href="http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx">Join-Object</a> blog post considering multiple joins and SQL style grouping and total evaluation.</p>
<p class="MsoNormal"><b>Problem:</b></p>
<p class="MsoNormal">In the <a href="http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx">Join-Object</a> blog we&rsquo;ve seen that relational data naturally organizes in multiple tables.&nbsp;Once we have those tables, we frequently want to see&nbsp;the information back together, so we need something like <a href="http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx">Join-Object</a>. Sometimes we also need to group the information and evaluate totals inside the groups. For instance, what are the total sales for each customer?</p>
<p class="MsoNormal">How can we use <a href="http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx">Join-Object</a><span class="MsoHyperlink"> </span>in multiple tables and group information from the tables to report totals?</p>
<p class="MsoNormal"><b>Joining multiple tables:</b></p>
<p class="MsoNormal">Consider the following tables describing sales at a fruit stand:</p>
<div align="center">
<table class="MsoTableGrid" style="border: currentColor; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="271" valign="top" style="padding: 0in 5.4pt; width: 203.4pt;" colspan="3">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: normal;"><b>Customers</b></p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Id</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Name</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Phone</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">1</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">John Smith</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">(206)555-8899</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">2</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Mark Stone</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">(425)999-8811</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">3</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Ruth Moore</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">(425)888-3355</p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal">&nbsp;</p>
<div align="center">
<table class="MsoTableGrid" style="border: currentColor; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="271" valign="top" style="padding: 0in 5.4pt; width: 203.4pt;" colspan="3">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;"><b>Products</b></p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Id</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Name</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Price</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">1</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Apple</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">10</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">2</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Orange</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">12</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">3</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Kiwi</p>
</td>
<td width="114" valign="top" style="padding: 0in 5.4pt; width: 85.5pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">15</p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal"><span style="line-height: 115%; font-size: 7pt;">&nbsp;</span></p>
<table align="center" class="MsoTableGrid" style="border: currentColor; margin-right: 6.75pt; margin-left: 6.75pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="319" valign="top" style="padding: 0in 5.4pt; width: 239.4pt;" colspan="3">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;"><b>Orders</b></p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Id</p>
</td>
<td width="174" valign="top" style="padding: 0in 5.4pt; width: 130.5pt; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Date</p>
</td>
<td width="102" valign="top" style="padding: 0in 5.4pt; width: 76.5pt; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">CustomerId</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">1</p>
</td>
<td width="174" valign="top" style="padding: 0in 5.4pt; width: 130.5pt; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/6/2012 9:12:44 AM</p>
</td>
<td width="102" valign="top" style="padding: 0in 5.4pt; width: 76.5pt; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">1</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">2</p>
</td>
<td width="174" valign="top" style="padding: 0in 5.4pt; width: 130.5pt; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/7/2012 6:12:10 PM</p>
</td>
<td width="102" valign="top" style="padding: 0in 5.4pt; width: 76.5pt; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">1</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">3</p>
</td>
<td width="174" valign="top" style="padding: 0in 5.4pt; width: 130.5pt; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/5/2012 12:05:03 PM</p>
</td>
<td width="102" valign="top" style="padding: 0in 5.4pt; width: 76.5pt; text-align: center;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">2</p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal">&nbsp;</p>
<table align="center" class="MsoTableGrid" style="border: currentColor; margin-right: 6.75pt; margin-left: 6.75pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="259" valign="top" style="padding: 0in 5.4pt; width: 2.7in;" colspan="4">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;"><b>OrderItems</b></p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p align="center" class="MsoNormal" style="text-align: center; line-height: 115%; margin-bottom: 10pt;">Id</p>
</td>
<td width="72" valign="top" style="padding: 0in 5.4pt; width: 0.75in;">
<p align="center" class="MsoNormal" style="text-align: center; line-height: 115%; margin-bottom: 10pt;">Quantity</p>
</td>
<td width="78" valign="top" style="padding: 0in 5.4pt; width: 58.5pt;">
<p align="center" class="MsoNormal" style="text-align: center; line-height: 115%; margin-bottom: 10pt;">ProductId</p>
</td>
<td width="66" valign="top" style="padding: 0in 5.4pt; width: 49.5pt;">
<p align="center" class="MsoNormal" style="text-align: center; line-height: 115%; margin-bottom: 10pt;">OrderId</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">1</p>
</td>
<td width="72" valign="top" style="padding: 0in 5.4pt; width: 0.75in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">2</p>
</td>
<td width="78" valign="top" style="padding: 0in 5.4pt; width: 58.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">3</p>
</td>
<td width="66" valign="top" style="padding: 0in 5.4pt; width: 49.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">1</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">2</p>
</td>
<td width="72" valign="top" style="padding: 0in 5.4pt; width: 0.75in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">1</p>
</td>
<td width="78" valign="top" style="padding: 0in 5.4pt; width: 58.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">2</p>
</td>
<td width="66" valign="top" style="padding: 0in 5.4pt; width: 49.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">1</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">3</p>
</td>
<td width="72" valign="top" style="padding: 0in 5.4pt; width: 0.75in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">4</p>
</td>
<td width="78" valign="top" style="padding: 0in 5.4pt; width: 58.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">5</p>
</td>
<td width="66" valign="top" style="padding: 0in 5.4pt; width: 49.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">1</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">4</p>
</td>
<td width="72" valign="top" style="padding: 0in 5.4pt; width: 0.75in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">5</p>
</td>
<td width="78" valign="top" style="padding: 0in 5.4pt; width: 58.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">1</p>
</td>
<td width="66" valign="top" style="padding: 0in 5.4pt; width: 49.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">2</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">5</p>
</td>
<td width="72" valign="top" style="padding: 0in 5.4pt; width: 0.75in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">4</p>
</td>
<td width="78" valign="top" style="padding: 0in 5.4pt; width: 58.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">2</p>
</td>
<td width="66" valign="top" style="padding: 0in 5.4pt; width: 49.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">2</p>
</td>
</tr>
<tr>
<td width="43" valign="top" style="padding: 0in 5.4pt; width: 0.45in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">6</p>
</td>
<td width="72" valign="top" style="padding: 0in 5.4pt; width: 0.75in;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">1</p>
</td>
<td width="78" valign="top" style="padding: 0in 5.4pt; width: 58.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">1</p>
</td>
<td width="66" valign="top" style="padding: 0in 5.4pt; width: 49.5pt;">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;">3</p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">As we saw in the <a href="http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx">Join-Object</a> blog, we need this many tables to deal with the simple conceptual problem of selling fruit!</p>
<p class="MsoNormal" style="text-align: justify;">One might question the need for the OrderItems table. An order item is a line in the receipt for an order that lists a product and its quantity. Since there can be many items per order, it needs its own table as mentioned in the <a href="http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx">Join-Object</a> blog.</p>
<p class="MsoNormal" style="text-align: justify;">As we can see from the data, we have 3 customers, 3 products, 3 orders, and 6 order items. The three first order items are for the Order with Id 1.</p>
<p class="MsoNormal" style="text-align: justify;">Good data design forces us to split the tables, but after this is done, we frequently need to see the data together.</p>
<p class="MsoNormal" style="text-align: justify;">For example, suppose I want a report with all basic receipt information, including customer name, order date, all products bought, their quantity, and price. Here is the SQL statement that produces the report:</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">SELECT&nbsp;&nbsp;&nbsp;&nbsp; Customer.Name, [Order].Date, OrderItem.Quantity,</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product.Name AS [Product Name], Product.Price</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OrderItem INNER JOIN Product ON OrderItem.ProductId = Product.id INNER JOIN</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Customer INNER JOIN&nbsp; [Order] ON Customer.id = [Order].CustomerId ON OrderItem.OrderId = [Order].id</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">&nbsp;</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">Here is the result:</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">&nbsp;</p>
<div align="center">
<table class="MsoTableGrid" style="border: currentColor; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="559" valign="top" style="padding: 0in 5.4pt; width: 419.4pt;" colspan="5">
<p align="center" class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: center; line-height: 115%;"><b>Joining All Tables</b></p>
</td>
</tr>
<tr>
<td width="115" valign="top" style="padding: 0in 5.4pt; width: 1.2in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Name</p>
</td>
<td width="156" valign="top" style="padding: 0in 5.4pt; width: 117pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Date</p>
</td>
<td width="112" valign="top" style="padding: 0in 5.4pt; width: 83.85pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Quantity</p>
</td>
<td width="128" valign="top" style="padding: 0in 5.4pt; width: 95.75pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Product Name</p>
</td>
<td width="49" valign="top" style="padding: 0in 5.4pt; width: 36.4pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Price</p>
</td>
</tr>
<tr>
<td width="115" valign="top" style="padding: 0in 5.4pt; width: 1.2in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">John Smith</p>
</td>
<td width="156" valign="top" style="padding: 0in 5.4pt; width: 117pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/6/2012 9:12:44 AM</p>
</td>
<td width="112" valign="top" style="padding: 0in 5.4pt; width: 83.85pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">2</p>
</td>
<td width="128" valign="top" style="padding: 0in 5.4pt; width: 95.75pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Apple</p>
</td>
<td width="49" valign="top" style="padding: 0in 5.4pt; width: 36.4pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">10</p>
</td>
</tr>
<tr>
<td width="115" valign="top" style="padding: 0in 5.4pt; width: 1.2in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">John Smith</p>
</td>
<td width="156" valign="top" style="padding: 0in 5.4pt; width: 117pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/6/2012 9:12:44 AM</p>
</td>
<td width="112" valign="top" style="padding: 0in 5.4pt; width: 83.85pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">1</p>
</td>
<td width="128" valign="top" style="padding: 0in 5.4pt; width: 95.75pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Orange</p>
</td>
<td width="49" valign="top" style="padding: 0in 5.4pt; width: 36.4pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">12</p>
</td>
</tr>
<tr>
<td width="115" valign="top" style="padding: 0in 5.4pt; width: 1.2in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">John Smith</p>
</td>
<td width="156" valign="top" style="padding: 0in 5.4pt; width: 117pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/6/2012 9:12:44 AM</p>
</td>
<td width="112" valign="top" style="padding: 0in 5.4pt; width: 83.85pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">4</p>
</td>
<td width="128" valign="top" style="padding: 0in 5.4pt; width: 95.75pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Kiwi</p>
</td>
<td width="49" valign="top" style="padding: 0in 5.4pt; width: 36.4pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">5</p>
</td>
</tr>
<tr>
<td width="115" valign="top" style="padding: 0in 5.4pt; width: 1.2in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">John Smith</p>
</td>
<td width="156" valign="top" style="padding: 0in 5.4pt; width: 117pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/7/2012 6:12:10 PM</p>
</td>
<td width="112" valign="top" style="padding: 0in 5.4pt; width: 83.85pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">5</p>
</td>
<td width="128" valign="top" style="padding: 0in 5.4pt; width: 95.75pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Apple</p>
</td>
<td width="49" valign="top" style="padding: 0in 5.4pt; width: 36.4pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">10</p>
</td>
</tr>
<tr>
<td width="115" valign="top" style="padding: 0in 5.4pt; width: 1.2in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">John Smith</p>
</td>
<td width="156" valign="top" style="padding: 0in 5.4pt; width: 117pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/7/2012 6:12:10 PM</p>
</td>
<td width="112" valign="top" style="padding: 0in 5.4pt; width: 83.85pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">4</p>
</td>
<td width="128" valign="top" style="padding: 0in 5.4pt; width: 95.75pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Orange</p>
</td>
<td width="49" valign="top" style="padding: 0in 5.4pt; width: 36.4pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">12</p>
</td>
</tr>
<tr>
<td width="115" valign="top" style="padding: 0in 5.4pt; width: 1.2in;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Mark Stone</p>
</td>
<td width="156" valign="top" style="padding: 0in 5.4pt; width: 117pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">6/5/2012 12:00:00 AM</p>
</td>
<td width="112" valign="top" style="padding: 0in 5.4pt; width: 83.85pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">1</p>
</td>
<td width="128" valign="top" style="padding: 0in 5.4pt; width: 95.75pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">Apple</p>
</td>
<td width="49" valign="top" style="padding: 0in 5.4pt; width: 36.4pt;">
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal;">10</p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;"><b>A little explanation of the SQL statement</b></p>
<p class="MsoNormal" style="text-align: justify;">The&nbsp; &ldquo;AS [Product Name]&rdquo; segment sets the column name in the output. Both product name and customer name are called &ldquo;Name&rdquo; in their own tables, so we need to differentiate them in the output.</p>
<p class="MsoNormal" style="text-align: justify;">The brackets around &ldquo;[Order]&rdquo; differentiate it from the SQL "Order" keyword.</p>
<p class="MsoNormal" style="text-align: justify;">The Inner Join shows only the items present in both tables.</p>
<p class="MsoNormal" style="text-align: justify;">All 4 tables are &ldquo;inner joined&rdquo; in the statement.</p>
<p class="MsoNormal" style="text-align: justify;"><b>&nbsp;</b></p>
<p class="MsoNormal" style="text-align: justify;"><b>Putting the data in Windows PowerShell</b></p>
<p class="MsoNormal" style="text-align: justify;">From here on, we will use Windows PowerShell to manipulate this data, so let&rsquo;s start by putting this data in PowerShell.</p>
<p class="MsoNormal" style="text-align: justify;">The following script creates four CSV files and then imports them into four variables that contain our data.</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">@"</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">Id,Name,Phone</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">1,John Smith,(206)555-8899</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">2,Mark Stone,(425)999-8811</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">3,Ruth Moore,(425)888-3355</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">"@</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">&gt;</span> <span style="color: blueviolet;">c:\temp\customers.csv</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$customers</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 9pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 9pt;">import-csv</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: blueviolet;">c:\temp\customers.csv</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">@"</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">Id,Name,Price</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">1,Apple,10</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">2,Orange,12</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">3,Kiwi,15</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">"@</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">&gt;</span> <span style="color: blueviolet;">c:\temp\products.csv</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$products</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 9pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 9pt;">import-csv</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: blueviolet;">c:\temp\products.csv</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">@"</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">Id,Date,CustomerId</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">1,6/6/2012 9:12:44 AM,1</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">2,6/7/2012 6:12:10 PM,1</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">3,6/5/2012 12:05:03 PM,2</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">"@</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">&gt;</span> <span style="color: blueviolet;">c:\temp\orders.csv</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$orders</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 9pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 9pt;">import-csv</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: blueviolet;">c:\temp\orders.csv</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">@"</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">Id,Quantity,ProductId,OrderId</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">1,2,1,1</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">2,1,2,1</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">3,4,3,1</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">4,5,1,2</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">5,4,2,2</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">6,1,1,3</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">"@</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">&gt;</span> <span style="color: blueviolet;">c:\temp\orderItems.csv</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$orderItems</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 9pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 9pt;">import-csv</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: blueviolet;">c:\temp\orderItems.csv</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">"Customers "</span><span style="font-family: 'Lucida Console'; font-size: 9pt;">;<span style="color: orangered;">$customers</span> <span style="color: darkgray;">|</span> <span style="color: blue;">format-table</span> <span style="color: navy;">-AutoSize</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">"`r`nProducts "</span><span style="font-family: 'Lucida Console'; font-size: 9pt;">;<span style="color: orangered;">$products</span> <span style="color: darkgray;">|</span> <span style="color: blue;">format-table</span> <span style="color: navy;">-AutoSize</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">"`r`nOrders "</span><span style="font-family: 'Lucida Console'; font-size: 9pt;">;<span style="color: orangered;">$orders</span> <span style="color: darkgray;">|</span> <span style="color: blue;">format-table</span> <span style="color: navy;">-AutoSize</span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkred; font-family: 'Lucida Console'; font-size: 9pt;">"`r`nOrder Items "</span><span style="font-family: 'Lucida Console'; font-size: 9pt;">;<span style="color: orangered;">$orderItems</span> <span style="color: darkgray;">|</span> <span style="color: blue;">format-table</span> <span style="color: navy;">-AutoSize </span></span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">Here is the output:</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Customers </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Id Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Phone </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">-- ----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ----- </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">1&nbsp; John Smith&nbsp; (206)555-8899</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">2&nbsp; Mark Stone&nbsp; (425)999-8811</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">3&nbsp; Ruth Moore&nbsp; (425)888-3355</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Products </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Id Name&nbsp;&nbsp;&nbsp; Price</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">-- ----&nbsp;&nbsp;&nbsp; -----</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">1&nbsp; Apple&nbsp;&nbsp; 10 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">2&nbsp; Orange&nbsp; 12 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">3&nbsp; Kiwi&nbsp;&nbsp;&nbsp; 15 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Orders </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Id Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomerId</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">-- ----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ----------</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">1&nbsp; 6/6/2012&nbsp; 9:12:44 AM 1 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">2&nbsp; 6/7/2012&nbsp; 6:12:10 PM 1 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">3&nbsp; 6/5/2012&nbsp; 12:05:03 PM 2 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Order Items </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Id Quantity ProductId OrderId</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">-- -------- --------- -------</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">1&nbsp; 2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;1 &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 1 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">2&nbsp; 1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 1 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">3&nbsp; 4&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;1 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">4&nbsp; 5&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;1&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;2 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">5&nbsp; 4&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;2&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 2 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">6&nbsp; 1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;1&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;3 </span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; line-height: normal; background: #012456; text-autospace: none;"><span style="font-size: 9.0pt; font-family: 'Lucida Console'; color: whitesmoke;">&nbsp;</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">The equivalent joins in PowerShell with the help of <a href="http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx">Join-Object</a> are as follows:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 8pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># Joins the customer to his orders and places Name(from Customer),</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># Date(from Order) and Id (from Order)</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 8pt;">$customerOrders</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 8pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 8pt;">Join-Object</span><span style="font-family: 'Lucida Console'; font-size: 8pt;"> <span style="color: navy;">-Left</span> <span style="color: orangered;">$customers</span> <span style="color: navy;">-Right</span> <span style="color: orangered;">$orders</span> <span style="color: navy;">-LeftProperties</span> <span style="color: blueviolet;">Name</span> <span style="color: navy;">-RightProperties</span> <span style="color: blueviolet;">Date</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">Id</span> <span style="color: navy;">-Where</span> {<span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">0</span><span style="color: darkgray;">].</span>Id <span style="color: darkgray;">-eq</span> <span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">1</span><span style="color: darkgray;">].</span>CustomerId}</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 8pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># Adds the OrderItems to the data already gathered. The output objects will</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># have Name(from Customer), Date(from Order), Quantity(from OrderItem) </span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># and ProductId (from OrderItem).</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 8pt;">$customerOrderItems</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 8pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 8pt;">Join-Object</span><span style="font-family: 'Lucida Console'; font-size: 8pt;"> <span style="color: navy;">-Left</span> <span style="color: orangered;">$customerOrders</span> <span style="color: navy;">-Right</span> <span style="color: orangered;">$orderItems</span> <span style="color: navy;">-LeftProperties</span> <span style="color: blueviolet;">Name</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">Date</span> <span style="color: navy;">-RightProperties</span> <span style="color: blueviolet;">Quantity</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">ProductId</span> <span style="color: navy;">-Where</span> {<span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">0</span><span style="color: darkgray;">].</span>Id <span style="color: darkgray;">-eq</span> <span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">1</span><span style="color: darkgray;">].</span>OrderId}</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 8pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># Adds the Products to the data already gathered. The output objects will</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># have Name (from Customer), Date(from Order), Quantity (from OrderItem)</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># Product Name (from Product) and Price from Product</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># We use a Hashtable instead of simply "Name" for Product Name because</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># "Name" is already present in the output object for the customer name,</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># so we need to differentiate the Product name from that.</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># If you did not know the syntax for the Hashtable Expression, you will</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: darkgreen; font-family: 'Lucida Console'; font-size: 8pt;"># be interested in the fact it also works for Select-Object properties</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 8pt;">$customerProducts</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 8pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 8pt;">Join-Object</span><span style="font-family: 'Lucida Console'; font-size: 8pt;"> <span style="color: navy;">-Left</span> <span style="color: orangered;">$customerOrderItems</span> <span style="color: navy;">-Right</span> <span style="color: orangered;">$products</span> <span style="color: navy;">-LeftProperties</span> <span style="color: blueviolet;">Name</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">Date</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">Quantity</span> <span style="color: navy;">-RightProperties</span> @{Name<span style="color: darkgray;">=</span><span style="color: darkred;">"Product Name"</span>;Expression<span style="color: darkgray;">=</span>{<span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Name}}<span style="color: darkgray;">,</span><span style="color: blueviolet;">Price</span> <span style="color: navy;">-Where</span> {<span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">0</span><span style="color: darkgray;">].</span>ProductId <span style="color: darkgray;">-eq</span> <span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">1</span><span style="color: darkgray;">].</span>Id}</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 8pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 8pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 8pt;">$customerProducts</span><span style="font-family: 'Lucida Console'; font-size: 8pt;"> <span style="color: darkgray;">|</span> <span style="color: blue;">format-table </span></span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: blue; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal">Here is the output:</p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Quantity Product Name Price</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -------- ------------ -----</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">John Smith 6/6/2012 9:12:44 AM&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">John Smith 6/6/2012 9:12:44 AM&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Orange&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">John Smith 6/6/2012 9:12:44 AM&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kiwi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 15&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">John Smith 6/7/2012 6:12:10 PM&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">John Smith 6/7/2012 6:12:10 PM&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Orange&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Mark Stone 6/5/2012 12:05:03 PM 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Apple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">So, the following three lines of code &hellip;</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 8pt;">$customerOrders</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 8pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 8pt;">Join-Object</span><span style="font-family: 'Lucida Console'; font-size: 8pt;"> <span style="color: navy;">-Left</span> <span style="color: orangered;">$customers</span> <span style="color: navy;">-Right</span> <span style="color: orangered;">$orders</span> <span style="color: navy;">-LeftProperties</span> <span style="color: blueviolet;">Name</span> <span style="color: navy;">-RightProperties</span> <span style="color: blueviolet;">Date</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">Id</span> <span style="color: navy;">-Where</span> {<span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">0</span><span style="color: darkgray;">].</span>Id <span style="color: darkgray;">-eq</span> <span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">1</span><span style="color: darkgray;">].</span>CustomerId}</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 8pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 8pt;">$customerOrderItems</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 8pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 8pt;">Join-Object</span><span style="font-family: 'Lucida Console'; font-size: 8pt;"> <span style="color: navy;">-Left</span> <span style="color: orangered;">$customerOrders</span> <span style="color: navy;">-Right</span> <span style="color: orangered;">$orderItems</span> <span style="color: navy;">-LeftProperties</span> <span style="color: blueviolet;">Name</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">Date</span> <span style="color: navy;">-RightProperties</span> <span style="color: blueviolet;">Quantity</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">ProductId</span> <span style="color: navy;">-Where</span> {<span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">0</span><span style="color: darkgray;">].</span>Id <span style="color: darkgray;">-eq</span> <span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">1</span><span style="color: darkgray;">].</span>OrderId}</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 8pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 8pt;">$customerProducts</span><span style="color: darkgray; font-family: 'Lucida Console'; font-size: 8pt;">=</span><span style="color: blue; font-family: 'Lucida Console'; font-size: 8pt;">Join-Object</span><span style="font-family: 'Lucida Console'; font-size: 8pt;"> <span style="color: navy;">-Left</span> <span style="color: orangered;">$customerOrderItems</span> <span style="color: navy;">-Right</span> <span style="color: orangered;">$products</span> <span style="color: navy;">-LeftProperties</span> <span style="color: blueviolet;">Name</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">Date</span><span style="color: darkgray;">,</span><span style="color: blueviolet;">Quantity</span> <span style="color: navy;">-RightProperties</span> @{Name<span style="color: darkgray;">=</span><span style="color: darkred;">"Product Name"</span>;Expression<span style="color: darkgray;">=</span>{<span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Name}}<span style="color: darkgray;">,</span><span style="color: blueviolet;">Price</span> <span style="color: navy;">-Where</span> {<span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">0</span><span style="color: darkgray;">].</span>ProductId <span style="color: darkgray;">-eq</span> <span style="color: orangered;">$args</span><span style="color: darkgray;">[</span><span style="color: purple;">1</span><span style="color: darkgray;">].</span>Id}</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">&hellip; do the same job as the SQL statement:</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">&nbsp;</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">SELECT&nbsp;&nbsp;&nbsp;Customer.Name, [Order].Date, OrderItem.Quantity,</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product.Name AS [Product Name], Product.Price</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OrderItem INNER JOIN Product ON OrderItem.ProductId = Product.id INNER JOIN</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Customer INNER JOIN&nbsp; [Order] ON Customer.id = [Order].CustomerId ON OrderItem.OrderId = [Order].id</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">&nbsp;</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: justify;">There are some advantages to the SQL statement:</p>
<p class="MsoListParagraphCxSpFirst" style="margin: 0pt; padding: 0pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">&middot;<span style="font: 7pt/normal 'Times New Roman'; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>It is a single statement that is somewhat shorter than the three statements&nbsp; in PowerShell.</p>
<p class="MsoListParagraphCxSpLast" style="margin: 0pt; padding: 0pt; text-align: justify; text-indent: -0.25in;"><span style="font-family: Symbol;">&middot;<span style="font: 7pt/normal 'Times New Roman'; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>It has a better syntax for aliasing a property in the output (&ldquo;as ProductName&rdquo; as opposed to &ldquo;<span style="line-height: 115%; font-family: 'Lucida Console'; font-size: 9pt;">@{Name<span style="color: darkgray;">=</span><span style="color: darkred;">"Product Name"</span>;Expression<span style="color: darkgray;">=</span>{<span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Name}}</span>&rdquo;).</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">In my opinion, those are small advantages. Each one of the PowerShell join statements is easy to understand in isolation. The hashtable syntax used in the third command (to change a property name) is a bit long, but very common to PowerShell users, because&nbsp; it is useful for other cmdlets including Select-Object.</p>
<p class="MsoNormal" style="text-align: justify;">I considered changing Join-Object to take all the lists and Where clauses in a single cmdlet call, but the need to pair each of two lists with a Where clause (and a Join type) makes the command a bit too cryptic for my taste. I prefer three statements that are easy to understand to one that is not. Performance-wise, there is no difference, because each Join has to be considered in isolation.</p>
<p class="MsoNormal" style="text-align: justify;">Now that the data is joined, what about getting the total money spent by each customer, the total money spent in each product and the total money spent?</p>
<p class="MsoNormal" style="text-align: justify;"><b>Total Money Spent by Each Customer</b></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;">Let&rsquo;s start with the whole command:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$customerProducts</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">|</span> <span style="color: blue;">Group-Object</span> <span style="color: blueviolet;">name</span> <span style="color: darkgray;">|</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">Select-Object</span> <span style="color: blueviolet;">Name</span><span style="color: darkgray;">,</span>@{Name<span style="color: darkgray;">=</span><span style="color: darkred;">'Total'</span>;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression<span style="color: darkgray;">=</span>{<span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Group <span style="color: darkgray;">|</span> <span style="color: blue;">ForEach-Object</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-Begin</span> {<span style="color: orangered;">$total</span><span style="color: darkgray;">=</span><span style="color: purple;">0</span>;} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-Process</span> {<span style="color: orangered;">$total</span><span style="color: darkgray;">+=[</span><span style="color: teal;">int</span><span style="color: darkgray;">]</span><span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Price<span style="color: darkgray;">*</span><span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Quantity} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-End</span> {<span style="color: orangered;">$total</span>}}} <span style="color: darkgray;">|</span> <span style="color: blue;">format-table</span>&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">It produces this output:</p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: courier new,courier; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sum</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: courier new,courier; font-size: 9pt;">----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ---</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: courier new,courier; font-size: 9pt;">John Smith 190</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: courier new,courier; font-size: 9pt;">Mark Stone&nbsp; 10</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">The first line:</p>
<p class="MsoNormal" style="text-align: justify;"><span style="color: orangered; line-height: 115%; font-family: 'Lucida Console'; font-size: 9pt;">$customerProducts</span><span style="line-height: 115%; font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">|</span> <span style="color: blue;">Group-Object</span> <span style="color: blueviolet;">name</span></span></p>
<p class="MsoNormal" style="text-align: justify;">Produces two groups:</p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: courier new,courier; font-size: 9pt;">Count Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: courier new,courier; font-size: 9pt;">----- ----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: courier new,courier; font-size: 9pt;">&nbsp;&nbsp;&nbsp; 5 John Smith&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {@{Name=John Smith; Date=6/6/2012 9:12:44 AM;...</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: courier new,courier; font-size: 9pt;">&nbsp;&nbsp;&nbsp; 1 Mark Stone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {@{Name=Mark Stone; Date=6/5/2012 12:05:03 PM;...&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">In order to better see what is in each group, we run:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">(<span style="color: orangered;">$customerProducts</span> <span style="color: darkgray;">|</span> <span style="color: blue;">Group-Object</span> <span style="color: blueviolet;">name</span>)<span style="color: darkgray;">[</span><span style="color: purple;">0</span><span style="color: darkgray;">].</span>Group </span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="text-align: justify;">Which produces:</p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6/6/2012 9:12:44 AM</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Quantity&nbsp;&nbsp;&nbsp; : 2</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">ProductName : Apple</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Price&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;: 10</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6/6/2012 9:12:44 AM</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Quantity&nbsp;&nbsp;&nbsp; : 1</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">ProductName : Orange</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 12</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6/6/2012 9:12:44 AM</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Quantity&nbsp;&nbsp;&nbsp; : 4</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">ProductName : Kiwi</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 15</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6/7/2012 6:12:10 PM</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Quantity&nbsp;&nbsp;&nbsp; : 5</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">ProductName : Apple</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 10</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : John Smith</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6/7/2012 6:12:10 PM</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Quantity&nbsp;&nbsp;&nbsp; : 4</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">ProductName : Orange</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 12 </span></p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">And:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">(<span style="color: orangered;">$customerProducts</span> <span style="color: darkgray;">|</span> <span style="color: blue;">Group-Object</span> <span style="color: blueviolet;">name</span>)<span style="color: darkgray;">[</span><span style="color: purple;">1</span><span style="color: darkgray;">].</span>Group </span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="text-align: justify;">Which produces:</p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Mark Stone</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6/5/2012 12:05:03 PM</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Quantity&nbsp;&nbsp;&nbsp; : 1</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">ProductName : Apple</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Price&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 10 </span></p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">So, inside the &ldquo;Group&rdquo; property of each object in the output of group-object is the Price and Quantity we want to multiply in order to get a total. If we wanted just the total quantity of fruit we could do:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$customerProducts</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">|</span> <span style="color: blue;">Group-Object</span> <span style="color: blueviolet;">name</span> <span style="color: darkgray;">|</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">Select-Object</span> <span style="color: blueviolet;">Name</span><span style="color: darkgray;">,</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; @{Name<span style="color: darkgray;">=</span><span style="color: darkred;">'Total'</span>;Expression<span style="color: darkgray;">=</span>{(<span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Group <span style="color: darkgray;">|</span> <span style="color: blue;">Measure-Object</span> <span style="color: blueviolet;">Quantity</span> <span style="color: navy;">-Sum</span>)<span style="color: darkgray;">.</span>Sum}} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; <span style="color: darkgray;">|</span> <span style="color: blue;">format-table</span>&nbsp; </span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal" style="text-align: justify;">With output:</p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Total</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -----</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">John Smith&nbsp;&nbsp;&nbsp; 16</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Mark Stone&nbsp;&nbsp;&nbsp;&nbsp; 1 </span></p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: blueviolet; font-family: 'Lucida Console';">Name</span> is the first column in the output. The second column is given by:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">@{Name<span style="color: darkgray;">=</span><span style="color: darkred;">'Total'</span>; Expression<span style="color: darkgray;">=</span>{(<span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Group <span style="color: darkgray;">|</span> <span style="color: blue;">Measure-Object</span> <span style="color: blueviolet;">Quantity</span> <span style="color: navy;">-Sum</span>)<span style="color: darkgray;">.</span>Sum}}</span></p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">This hashtable is a syntax for select object which means a column with a Name = Total and a value which is the Expression. The Expression gets the value of the Group property and pipes to Measure-Object to sum the &lsquo;Quantity&rsquo; property of each member of the Group. Finally the Sum property of the Measure-Object result is retrieved. That property contains the actual sum.</p>
<p class="MsoNormal" style="text-align: justify;">Since we want to get Price * Quantity and measure-object only supports plain properties we end up with the full command repeated here:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$customerProducts</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">|</span> <span style="color: blue;">Group-Object</span> <span style="color: blueviolet;">name</span> <span style="color: darkgray;">|</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">Select-Object</span> <span style="color: blueviolet;">Name</span><span style="color: darkgray;">,</span>@{Name<span style="color: darkgray;">=</span><span style="color: darkred;">'Total'</span>;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression<span style="color: darkgray;">=</span>{<span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Group <span style="color: darkgray;">|</span> <span style="color: blue;">ForEach-Object</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-Begin</span> {<span style="color: orangered;">$total</span><span style="color: darkgray;">=</span><span style="color: purple;">0</span>;} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-Process</span> {<span style="color: orangered;">$total</span><span style="color: darkgray;">+=[</span><span style="color: teal;">int</span><span style="color: darkgray;">]</span><span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Price<span style="color: darkgray;">*</span><span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Quantity} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-End</span> {<span style="color: orangered;">$total</span>}}} <span style="color: darkgray;">|</span> <span style="color: blue;">format-table</span>&nbsp;&nbsp; </span></p>
<p class="MsoNormal" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">Instead of | measure-object we have a | ForEach-Object where we use &ndash;Begin, -Process and &ndash;End to evaluate the total. This could be easily modified to calculate anything else, including averages, standard deviations, etc.</p>
<p class="MsoNormal"><span style="line-height: 115%; font-size: 4pt;">&nbsp;</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt; text-align: justify;">Note: The [int] cast in front of $_.Price is required because the price is a string out of our CSV file. This could be avoided by using Export-CliXml and Import-CliXml for our data, whioch would preserve the data type.</p>
<p class="MsoListParagraph" style="text-align: justify;">&nbsp;</p>
<p class="MsoNormal" style="text-align: justify;">Here is the corresponding SQL statement:</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">SELECT&nbsp;&nbsp;&nbsp;Customer.Name, <b>SUM(OrderItem.Quantity * Product.Price)</b> AS SUM</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OrderItem INNER JOIN</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Product ON OrderItem.ProductId = Product.id INNER JOIN</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Customer INNER JOIN</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Order] ON Customer.id = [Order].CustomerId ON OrderItem.OrderId = [Order].id</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;"><b>GROUP BY Customer.Name</b></span></p>
<p class="MsoNormal"><b>&nbsp;</b></p>
<p class="MsoNormal" style="text-align: justify;">The SQL statement combines the joining, grouping and total evaluation(Price * Quantity) operations.</p>
<p class="MsoNormal" style="text-align: justify;">The Powershell statement is only doing the grouping and total evaluation, since the $customerProducts variable has the result of the joins performed in the previous section of this blog post.</p>
<p class="MsoNormal" style="text-align: justify;">The bold segments of the SQL statement are performing the grouping and the PowerShell statement.</p>
<p class="MsoNormal" style="text-align: justify;">SQL is designed specifically for this kind of data, so it provides a shorter syntax overall, but I believe the PowerShell equivalent is simple enough to understand.</p>
<p class="MsoNormal" style="text-align: justify;"><b>Total Money Spent in Each Product</b></p>
<p class="MsoNormal" style="text-align: justify;">The only thing that changes from the previous section is that the property we&rsquo;re passing to Group-Object is &ldquo;ProductName&rdquo;:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$customerProducts</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">|</span> <span style="color: blue;">Group-Object</span> <span style="color: blueviolet;">ProductName</span> <span style="color: darkgray;">|</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">Select-Object</span> <span style="color: blueviolet;">Name</span><span style="color: darkgray;">,</span>@{Name<span style="color: darkgray;">=</span><span style="color: darkred;">'Total'</span>;</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression<span style="color: darkgray;">=</span>{<span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Group <span style="color: darkgray;">|</span> <span style="color: blue;">ForEach-Object</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-Begin</span> {<span style="color: orangered;">$total</span><span style="color: darkgray;">=</span><span style="color: purple;">0</span>;} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-Process</span> {<span style="color: orangered;">$total</span><span style="color: darkgray;">+=[</span><span style="color: teal;">int</span><span style="color: darkgray;">]</span><span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Price<span style="color: darkgray;">*</span><span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Quantity} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-End</span> {<span style="color: orangered;">$total</span>}}} <span style="color: darkgray;">|</span> <span style="color: blue;">format-table</span>&nbsp;&nbsp; </span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Name&nbsp;&nbsp; Sum</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">----&nbsp;&nbsp; ---</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Apple&nbsp;&nbsp; 80</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Orange&nbsp; 60</span></p>
<p class="MsoNormal" style="background: #012456; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: whitesmoke; font-family: 'Lucida Console'; font-size: 9pt;">Kiwi&nbsp;&nbsp;&nbsp; 60 </span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">The corresponding SQL is:</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">SELECT&nbsp;&nbsp;Product.Name, <b>SUM(OrderItem.Quantity * Product.Price)</b> AS Sum</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">FROM&nbsp;&nbsp;&nbsp;&nbsp;OrderItem INNER JOIN</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product ON OrderItem.ProductId = Product.id</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;"><b>GROUP BY Product.Name</b></span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><b>Total Money Spent</b></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;">Here is the command that produces this total:</p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="color: orangered; font-family: 'Lucida Console'; font-size: 9pt;">$customerProducts</span><span style="font-family: 'Lucida Console'; font-size: 9pt;"> <span style="color: darkgray;">|</span> <span style="color: blue;">ForEach-Object</span> `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-Begin</span> {<span style="color: orangered;">$total</span><span style="color: darkgray;">=</span><span style="color: purple;">0</span>;} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-Process</span> {<span style="color: orangered;">$total</span><span style="color: darkgray;">+=[</span><span style="color: teal;">int</span><span style="color: darkgray;">]</span><span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Price<span style="color: darkgray;">*</span><span style="color: orangered;">$_</span><span style="color: darkgray;">.</span>Quantity} `</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: navy;">-End</span> {<span style="color: orangered;">$total</span>}</span></p>
<p class="MsoNormal" style="background: white; margin: 0pt; padding: 0pt; line-height: normal;"><span style="font-family: 'Lucida Console'; font-size: 9pt;">&nbsp;</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">Here is the corresponding SQL:</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">SELECT&nbsp; <b>SUM(OrderItem.Quantity * Product.Price)</b> AS Sum</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">FROM&nbsp;&nbsp;&nbsp;&nbsp;OrderItem INNER JOIN</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product ON OrderItem.ProductId = Product.id</span></p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">&nbsp;</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">&nbsp;</p>
<p class="MsoNormal" style="margin: 0pt; padding: 0pt;">Lucio Silveira[MSFT]</p>
</div><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10355722" width="1" height="1"></description></item><item><title>Windows Management Framework 3.0 Available for Download</title><link>http://blogs.msdn.com/b/powershell/archive/2012/09/17/windows-management-framework-3-0-available-for-download.aspx</link><pubDate>Mon, 17 Sep 2012 19:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10350225</guid><dc:creator>PowerShell Team</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/powershell/rsscomments.aspx?WeblogPostID=10350225</wfw:commentRss><comments>http://blogs.msdn.com/b/powershell/archive/2012/09/17/windows-management-framework-3-0-available-for-download.aspx#comments</comments><description><p>We hope that you&rsquo;ve been enjoying all of the great new Windows PowerShell 3.0 features in <a href="http://www.windows-server-launch.com/">Windows Server 2012</a>. We wanted to make sure that everyone knows the final release of Windows Management Framework 3.0 is also available for download from the <a href="http://go.microsoft.com/fwlink/?LinkId=251995">Microsoft Download Center</a>.</p>
<p>Windows Management Framework 3.0 makes much of the same great management functionality from Windows Server 2012 available to earlier versions of Windows. Windows Management Framework 3.0 allows you to install Windows PowerShell 3.0 (including a new version of WMI and WinRM) on the following Operating Systems:</p>
<ul>
<li>Windows 7 Service Pack 1 (32-bit &amp; 64-bit)</li>
<li>Windows Server 2008 R2 Service Pack 1 (64-bit only, includes Server Core)&nbsp;</li>
<li>Windows Server 2008 Service Pack 2 (32-bit &amp; 64-bit)</li>
</ul>
<p>&nbsp;</p>
<p>Note: You must uninstall any of the pre-release packages of Windows Management Framework prior to installing the final release.</p>
<p>&nbsp;</p>
<p>Travis Jones [MSFT] <br />Program Manager &ndash; Windows PowerShell <br />Microsoft Corporation</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10350225" width="1" height="1"></description></item><item><title>Managing Hardware devices from PowerShell</title><link>http://blogs.msdn.com/b/powershell/archive/2012/09/10/managing-hardware-devices-from-powershell.aspx</link><pubDate>Mon, 10 Sep 2012 17:52:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10347897</guid><dc:creator>PowerShell Team</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/powershell/rsscomments.aspx?WeblogPostID=10347897</wfw:commentRss><comments>http://blogs.msdn.com/b/powershell/archive/2012/09/10/managing-hardware-devices-from-powershell.aspx#comments</comments><description><p>Steve did a very cool blog post last month about managing hardware that implements standard DMTF profiles (examples: Intel AMT , Broadcom TruManage )</p>
<p><a href="http://blogs.msdn.com/b/wmi/archive/2012/08/08/standards-based-hardware-management-using-powershell.aspx">http://blogs.msdn.com/b/wmi/archive/2012/08/08/standards-based-hardware-management-using-powershell.aspx</a></p>
<p>He has also published a PowerShell module on TechNet script center to help IT Pros. This module has been built on top of new CIM Cmdlets.</p>
<p><a href="http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Out-of-Band-84009c12">http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Out-of-Band-84009c12</a></p>
<p>&nbsp;</p>
<p>Take a look, and send your feedback.</p>
<p>Osama Sajid</p>
<p>Program Manager, WMI</p>
<p>&nbsp;</p>
<p>&nbsp;</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10347897" width="1" height="1"></description><category domain="http://blogs.msdn.com/b/powershell/archive/tags/WMI/">WMI</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/CIM/">CIM</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/DMTF/">DMTF</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/Hardware+Management/">Hardware Management</category></item><item><title>Introduction to CIM Cmdlets</title><link>http://blogs.msdn.com/b/powershell/archive/2012/08/24/introduction-to-cim-cmdlets.aspx</link><pubDate>Fri, 24 Aug 2012 22:42:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10343415</guid><dc:creator>PowerShell Team</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/powershell/rsscomments.aspx?WeblogPostID=10343415</wfw:commentRss><comments>http://blogs.msdn.com/b/powershell/archive/2012/08/24/introduction-to-cim-cmdlets.aspx#comments</comments><description><p>PowerShell 3.0 shipping with Windows server 2012 and Windows 8 brings a new set of Cmdlets to manage any server or device that complies with CIM and WS-Man standards defined by DMTF. In this blog post we will explore these new Cmdlets and how can they help IT Pros in managing a datacenter.</p> <p>The list of new Cmdlets is given in the table below: <table border="1" cellspacing="0" cellpadding="0" width="668"><tbody> <tr> <td valign="top" width="205"> <p><b>Cmdlet</b></p> </td> <td valign="top" width="461"> <p><b>Purpose</b></p> </td> </tr> <tr> <td valign="top" width="205"> <p>Get-CimInstance</p> </td> <td valign="top" width="461"> <p>Gets instances of a class.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>New-CimInstance</p> </td> <td valign="top" width="461"> <p>Creates a new instance of a class.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>Remove-CimInstance</p> </td> <td valign="top" width="461"> <p>Removes one of more instances of a class.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>Set-CimInstance</p> </td> <td valign="top" width="461"> <p>Modifies one or more instances of a class.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>Get-CimAssociatedInstance</p> </td> <td valign="top" width="461"> <p>Gets all the associated instances for a particular instance.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>Invoke-CimMethod</p> </td> <td valign="top" width="461"> <p>Invokes instance or static method of a class.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>Get-CimClass</p> </td> <td valign="top" width="461"> <p>Gets class schema of a CIM class.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>Register-CimIndicationEvent</p> </td> <td valign="top" width="461"> <p>Helps subscribe to events.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>New-CimSession</p> </td> <td valign="top" width="461"> <p>Creates a CIM Session with local or a remote machine</p> </td> </tr> <tr> <td valign="top" width="205"> <p>Get-CimSession</p> </td> <td valign="top" width="461"> <p>Gets a list of CIM Sessions that have been made.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>Remove-CimSession</p> </td> <td valign="top" width="461"> <p>Removes CimSessions that are there on a machine.</p> </td> </tr> <tr> <td valign="top" width="205"> <p>New-CimSessionOption</p> </td> <td valign="top" width="461"> <p>Creates a set of options that can be used while creating a CIM session.</p> </td> </tr> </tbody></table> </p> <p>&#160;</p> <h3>Basic terminology</h3> <p>If you are already familiar with terms like WMI, CIM, WinRM and WS-Man, you can skip this section.</p> <p><b>CIM</b>: Common Information Model (CIM) is the DMTF standard [DSP0004] for describing the structure and behavior of managed resources such as storage, network, or software components.</p> <p><b>WMI</b>: Windows Management Instrumentation (WMI) is a CIM server that implements the CIM standard on Windows. </p> <p><b>WS-Man</b>: WS-Management (WS-Man) protocol is a SOAP-based, firewall-friendly protocol for management clients to communicate with CIM servers.</p> <p><b>WinRM:</b> Windows Remote Management (WinRM) is the Microsoft implementation of the WS-Man protocol on Windows.</p> <p>&#160;</p> <h3>Why new Cmdlets</h3> <p>With Windows Server 2012, Windows has shifted its focus to become a Cloud OS. In a datacenter running a private or public cloud – there are always set of devices and servers from different vendors. We strongly believe that the only way to reduce the cost of running datacenters is through automation built on top of standards. There is less learning and less chances of error when IT Pros are able to automate heterogeneous environment using same set of tools that they have learned for Windows.</p> <p>This was not the case with previous versions of PowerShell. We had two set of Cmdlets to manage Windows and Non-Windows. WMI Cmdlets were primarily used to manage Windows and WsMan Cmdlets were targeted at non-Windows that implemented WsMan standard.</p> <p><b>WMI Cmdlets: </b></p> <blockquote> <p>- Pros: Provided better task abstraction compared to WsMan Cmdlets, output is a .NET object.</p> </blockquote> <blockquote> <p>- Cons: Use of non-standard DCOM protocol. Does not work for non-Windows. <b></b></p> </blockquote> <p><b>WinRM Cmdlets</b></p> <blockquote> <p>- Pros: Works with Windows and non-Windows using standard protocol.</p> </blockquote> <blockquote> <p>- Cons: Poor task abstraction. Output is XML , scaring most IT Pros away</p> </blockquote> <p>We heard from you that the major obstacle in PS scripting for WMI is lack of discoverability. We also heard that WMI Cmdlets don’t provide first class PS experience. There are issues with serializing a WMI object, there is no concept of session reuse and WMI object has weird looking property names (like __Server). Last but not least, there is poor formatting for most of the commonly used WMI classes. Someone said “When I run Get-WmiObject Win32_process, I feel like standing on bridge above freeway and lot of traffic zipping in front of my eyes”.</p> <h3>Key goals for new CIM Cmdlets</h3> <blockquote> <p>- <strong>Rich PowerShell experience</strong>. Make CIM a first class citizen of PS, addressing usability concerns and user feedback for WMI and WsMan Cmdlets. </p> </blockquote> <blockquote> <p>- <strong>Standard compliance</strong>. With so much focus on standards, our goal is to make PowerShell the best platform for managing Windows and Non-Windows. New CIM Cmdlets should be able to manage any CIM + WsMan compliant endpoint, including Windows.</p> </blockquote> <blockquote> <p>- <strong>Support for down-level machines</strong>. We understand that there are more down-level servers in a datacenter than there would be Windows Server 2012 for some time to come. We want to make sure same set of Cmdlets can be used to manage down-level Windows as well.</p> </blockquote> <p>In the subsequent sections we will talk about each of these goals in detail.</p> <p>&#160;</p> <h3><u>Goal 1 - Rich PowerShell experience</u> </h3> <h4><strong>1. Discovery of classes and namespaces.</strong></h4> <p>There is a famous joke about WMI, often attributed to Jeffrey Snover. “IT Pros love and hate WMI. They love it because there is so much they accomplish with WMI and PowerShell. They hate it because it is very difficult to discover what’s in there”</p> <p>To address this, we have done key improvements in new CIM Cmdlets</p> <ol> <li>Tab completion for classname and namespace parameters. </li> <li>Get-CimClass Cmdlet </li> </ol> <p> <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" bgcolor="#000066"><tbody> <tr> <td valign="top" width="638"> <p># Using tab completion for CIM cmdlet parameters ( Tab+Space in ISE shows a drop down)</p> <p>Get-CimInstance –Namespace &lt;Tab&gt; #Finding top-level namespaces</p> <p># Tab completion for class names</p> <p># If namespace is not specified, shows classes from default root/cimv2 namespace</p> <p>Get-CimInstance -ClassName *Bios&lt;Tab&gt;</p> <p>Get-CimInstance –Namespace root/Microsoft/Windows/smb –ClassName &lt;tab&gt;</p> <p># Note: Tab completion only works for local machine.</p> <p>#Using Get-CimClass for advanced class search</p> <p>#All classes in root/cimv2</p> <p>PS:&gt;Get-CimClass </p> <p>#Classes named like disk</p> <p>PS:&gt;Get-CimClass -ClassName *disk*</p> <p># The Cmdlet makes querying much easier (what would require scripting before)</p> <p># Get all classes starting with &quot;Win32&quot; that have method starting with &quot;Term&quot; </p> <p>PS:&gt;Get-CimClass Win32* -MethodName Term* </p> <p># Get classes starting with &quot;Win32&quot; that have a property named &quot;Handle&quot;</p> <p>PS:&gt;Get-CimClass Win32* -PropertyName Handle</p> <p># Get classes starting with &quot;Win32&quot; that have the &quot;Association&quot; qualifier</p> <p>PS:&gt;Get-CimClass Win32* -QualifierName Association</p> <p>#Find classes used for events</p> <p>PS:&gt; Get-CimClass -Namespace root/Microsoft/Windows/smb -class *Smb* -QualifierName Indication</p> </td> </tr> </tbody></table> </p> <p>Get-CimClass and tab completion described above only works for local machine. If you specify ComputerName or CimSession parameter, tab completion would not work. In order to make tab completion more efficient, PowerShell caches the list of namespaces and classnames.</p> <h4><strong>2. Getting Instances</strong></h4> <p>Getting/Enumerating instance of a class is the most commonly performed operation. We wanted the new Get-CimInstance Cmdlet to have better performance and even better user experience as compared to the old Get-WmiObject cmdlet. To achieve these goals we made the following design decisions:</p> <p>a. The Get-CimInstance cmdlet returns one or more instances of CimInstance. CimInstance is different from the object returned by Get-WmiObject. </p> <p>b. __Properties are no longer mixed with properties of an instance.</p> <p>c. Reduce memory and on-the-wire footprint by allowing retrieval of a subset of properties. </p> <p>d. Allow retrieval of key properties.</p> <p>e. Allow creation of in-memory instance to reduce round trips.</p> <p>f. Allow retrieval of specific instances using in-memory instances or actual instances.</p> <p>g. DateTime values are returned as objects of System.DateTime type. Old cmdlets treat them as strings.</p> <p>&#160;</p> <p> <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" bgcolor="#000066"><tbody> <tr> <td valign="top" width="638"> <p># Get-CimInstance was designed to be similar to the Get-WmiObject</p> <p># WMI Cmdlet : Get-WmiObject -class Win32_Process</p> <p># WsMan Cmdlet : get-wsmaninstance wmicimv2/win32_process -Enumerate</p> <p># The default value of -Namespace is root/cimv2, and the default value of -ComputerName is local computer </p> <p>PS:&gt; Get-CimInstance -Class Win32_Process</p> <p># Filtering using WQL</p> <p>PS:&gt; Get-CimInstance -Query &quot;SELECT * FROM Win32_Process WHERE Name Like 'power%'&quot; </p> <p># use the -Filter parameter with -classname</p> <p>PS:&gt; Get-CimInstance -Class Win32_Process -Filter &quot;Name Like 'power%'&quot; </p> <p>#Retrieving a subset of properties : To reduce memory and on-the-wire footprint</p> <p>PS:&gt; Get-CimInstance -Class Win32_Process -Property Name, Handle </p> <p>#Only get the key properties</p> <p>PS:&gt; Get-CimInstance -Class Win32_Process -KeyOnly</p> <p>########################## Looking into CimInstance #########################</p> <p>PS:&gt;&#160; $x, $y = Get-CimInstance Win32_Process</p> <p>PS:&gt;&#160; $x | gm</p> <p># The object contains the full CIM class derivation hierarchy</p> <p>PS:&gt; $x.pstypenames</p> <p># The object also has a reference to its class declaration</p> <p>PS:&gt; $x.CimClass | gm</p> <p># DateTime values are returned as strings</p> <p>PS:&gt; Get-WmiObject Win32_OperatingSystem | Select *Time*</p> <p># DateTime values are returned as System.DateTime</p> <p>PS:&gt; Get-CimInstance Win32_OperatingSystem | Select *Time*#</p> </td> </tr> </tbody></table> </p> <h4><strong>3. Working with associations</strong></h4> <p>Working with associations was not straight forward in the old WMI cmdlets. Customers wanted a way to find out associated instances of a particular instance. To resolve this issue we came up with a cmdlet called Get-CimAssociatedInstance. The following example shows some of the important features of this cmdlet.</p> <p> <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" bgcolor="#000066"><tbody> <tr> <td valign="top" width="638"> <p># Get instance of Win32_LogicalDisk class with DriveType =3 (hard drives)</p> <p>PS:&gt; $disk1, $diskn = Get-CimInstance -class Win32_LogicalDisk -Filter 'DriveType = 3'</p> <p>PS:&gt; $disk1</p> <p># Get the all instances associated with this disk</p> <p>PS:&gt; Get-CimAssociatedInstance -CimInstance $disk1</p> <p># Get instances of a specific type</p> <p>PS:&gt; Get-CimAssociatedInstance -CimInstance $disk1 -ResultClassName Win32_DiskPartition</p> <p># Finding associated instances through a specific CIM relationship </p> <p>PS:&gt; Get-CimAssociatedInstance -CimInstance $diskn -Association Win32_LogicalDiskRootDirectory</p> </td> </tr> </tbody></table> </p> <h4><strong>4. Working with methods</strong></h4> <p>A large number of tasks in WMI are achieved by invoking methods. The new Invoke-CimMethod makes two things really easy: </p> <blockquote> <p>a. Discovery of method and method parameters</p> </blockquote> <blockquote> <p>b. Execution of methods with parameters. Using feedback from our customers: <a href="https://connect.microsoft.com/PowerShell/feedback/details/624263/invoking-wmi-methods-with-invoke-wmimethod">Connect bug</a></p> </blockquote> <p>The following examples show how easy it is to discover and execute methods using Invoke-CimMethod: </p> <p> <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" width="725" bgcolor="#000066"><tbody> <tr> <td valign="top" width="723"> <p>PS:&gt; $class = Get-CimClass Win32_Process</p> <p>PS:&gt; $class.CimClassMethods</p> <p># Get the parameters of the Create method</p> <p>PS:&gt; $class.CimClassMethods[&quot;Create&quot;].Parameters</p> <p># Invoke the static Create method on the Win32_Process class to create an instance of the Notepad </p> <p># application. Notice that the method parameters are given in a hash table since CIM method arguments</p> <p># are unordered by definition. </p> <p>PS:&gt; Invoke-CimMethod -Class win32_process -MethodName Create -Argument @{CommandLine='notepad.exe';</p> <p>CurrentDirectory = &quot;c:\windows\system32&quot;}</p> <p># Get the owners of the running Notepad instances</p> <p>PS:&gt; $result = Invoke-CimMethod -Query 'SELECT * FROM Win32_Process WHERE name like &quot;notepad%&quot;' </p> <p>-MethodName GetOwner</p> <p># The result has the returned value and out parameters of the method</p> <p>PS:&gt; $result</p> </td> </tr> </tbody></table> </p> <h4><strong>5. CliXML serialization.</strong></h4> <p>CimInstance supports full fidelity serialization and deserialization. This is an important feature for those who wish to save state of an instance or result of a cmdlet and then want to use it later. The WMI cmdlets do not support full-fidelity serialization/deserialization. <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" bgcolor="#000066"><tbody> <tr> <td valign="top" width="638"> <p># CimInstances are serialized and deserialized with full fidelity</p> <p>PS:&gt; $x = Get-CimInstance Win32_Service </p> <p>PS:&gt; $x</p> <p>PS:&gt; $x[0].pstypenames</p> <p>PS:&gt; $x | Export-CliXml t1.xml</p> <p>PS:&gt; $y = Import-CliXml .\t1.xml</p> <p>PS:&gt; $y</p> <p>PS:&gt; $y[0].pstypenames</p> <p># The deserialized objects are identical to the ones obtained from the server</p> <p>PS:&gt; diff ($y) (Get-CimInstance win32_service )</p> </td> </tr> </tbody></table> </p> <h4><strong>6. Remote management</strong></h4> <p>Managing remote machines with the new cmdlets is also pretty simple and straight forward. The two parameters that can be used to manage remote machines are:</p> <blockquote> <p>a. ComputerName</p> </blockquote> <blockquote> <p>b. CimSession</p> </blockquote> <p>The following example will explain how these two parameters can be used to manage a remote machine. </p> <p> <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" width="729" bgcolor="#000066"><tbody> <tr> <td valign="top" width="727"> <p>PS:&gt; $props = @{v_Key = [UInt64] 8;}</p> <p># If ComputerName parameter is used, the cmdlets create an implicit session during the execution.</p> <p>PS:&gt; $inst = New-CimInstance -ClassName TestClass -Namespace root\test -Key v_Key -Property $props </p> <p>-ComputerName SecondWin8Server</p> <p># Create a session</p> <p>PS:&gt; $session = New-CimSession –ComputerName SecondWin8Server</p> <p># Use the session </p> <p>PS:&gt; $inst = New-CimInstance -ClassName TestClass -Namespace root\test -Key v_Key -Property $props </p> <p>–CimSession $session</p> </td> </tr> </tbody></table> </p> <p><strong>Tip:</strong> If a large number of remote operations are to be performed then session reuse is highly recommended. This can provide a significant performance gain.</p> <h4><strong>7. Easy migration from WMI cmdlets</strong></h4> <p>Last, but not the least, a very important aspect is to reduce learning. If you know how to use WMI cmdlets from PowerShell 2.0, you will find learning new CIM cmdlets easy. These cmdlets follow similar patterns as WMI cmdlets -including parameter names and alias. Let’s see how easy or difficult it is to move to new cmdlets <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" bgcolor="#000066"><tbody> <tr> <td valign="top" width="638"> <p><b># OLD: One liner to get ComputerSystem information</b></p> <p>PS:&gt; Get-WmiObject Win32_ComputerSystem</p> <p><b># NEW:</b></p> <p>PS:&gt; Get-CimInstance Win32_ComputerSystem</p> <p># ClassName is position and mandatory.</p> <p># Namespace default is root/cimv2 namespace</p> <p>#WMI Cmdlet – with classnames and Namespace</p> <p>PS:&gt; Get-WmiObject –ClassName Win32_Process –Namespace root/cimv2</p> <p>#CIM cmdlet follows the same pattern</p> <p>PS:&gt; Get-CimInstance –ClassName Win32_Process –Namespace root/cimv2</p> </td> </tr> </tbody></table> </p> <p>The table below shows the list of WMI cmdlets and their CIM equivalent: <table border="1" cellspacing="0" cellpadding="0"><tbody> <tr> <td valign="top" width="319"> <p><b>Old cmdlet</b></p> </td> <td valign="top" width="319"> <p><b>New Cmdlet</b></p> </td> </tr> <tr> <td valign="top" width="319"> <p>Get-WmiObject</p> </td> <td valign="top" width="319"> <p>Get-CimInstance</p> </td> </tr> <tr> <td valign="top" width="319"> <p>Get-WmiObject -list</p> </td> <td valign="top" width="319"> <p>Get-CimClass</p> </td> </tr> <tr> <td valign="top" width="319"> <p>Set-WmiInstance</p> </td> <td valign="top" width="319"> <p>Set-CimInstance</p> </td> </tr> <tr> <td valign="top" width="319"> <p>Set-WmiInstance –PutType CreateOnly</p> </td> <td valign="top" width="319"> <p>New-CimInstance</p> </td> </tr> <tr> <td valign="top" width="319"> <p>Remove-WmiObject</p> </td> <td valign="top" width="319"> <p>Remove-CimInstance </p> </td> </tr> <tr> <td valign="top" width="319"> <p>Invoke-WmiMethod</p> </td> <td valign="top" width="319"> <p>Invoke-CimMethod</p> </td> </tr> </tbody></table> </p> <p><b>Note: </b>In old cmdlets Set-WmiInstance was used to perform update and create operations. The new cmdlets clearly define the distinction between the two operations i.e. New-CimInstance is used to create an instance and Set-CimInstance is used to update an existing instance.</p> <p>You will also notice that in some places we have broken this rule – and script using WMI cmdlet can’t be simply changed to CIM cmdlet by changing the cmdlet name. e.g. <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" bgcolor="#000066"><tbody> <tr> <td valign="top" width="638"> <p><b># OLD:</b></p> <p>PS:&gt; Invoke-WMIMethod -class Win32_Process -Name create -ArgumentList 'calc.exe'</p> <p><b># NEW:</b></p> <p>PS:&gt;Invoke-CimMethod Win32_Process -MethodName create -Arguments @{CommandLine='calc.exe'}</p> <p>New Cmdlet takes a hash table or ordered dictionary as input not an Object.</p> </td> </tr> </tbody></table> </p> <p>The rule here is, if the WMI cmdlet experience is not ideal, we don’t want to carry it forward. It’s better to break a bad experience (like in the example given above)</p> <p>&#160;</p> <h3><u>Goal 2 - Standard Compliance</u></h3> <p>· CIM cmdlets are modeled on generic CIM operations</p> <p>· Work over WsMan for remote management, making it possible to manage any server or device that implements WsMan and CIM standard.</p> <p>· Removes the need to build custom agents and/or protocol to manage complex heterogeneous environments</p> <p>· CIM cmdlets will work seamlessly with the new Open Management Infrastructure. <a href="http://blogs.technet.com/b/windowsserver/archive/2012/06/28/open-management-infrastructure.aspx">http://blogs.technet.com/b/windowsserver/archive/2012/06/28/open-management-infrastructure.aspx</a></p> <p>The following example shows that CimCmdlets can be used to manage a non-windows device (i.e. an Intel AMT box): <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" bgcolor="#000066"><tbody> <tr> <td valign="top" width="638"> <p># Save credentials in an object</p> <p>PS:&gt; $cred = Get-Credential -UserName admin</p> <p># Create a session with Intel AMT machine.</p> <p>PS:&gt; $s = New-CimSession -ComputerName $serverAMT -Port 16992 -Authentication Digest -Credential $cred</p> <p># Use classname to get instances from an Intel AMT machine.</p> <p>PS:&gt; Get-CimInstance -class CIM_ComputerSystem -Namespace interop -CimSession $s</p> <p># Use resourceURI to get instances from an Intel AMT machine.</p> <p>PS:&gt; $resourceURI = “http://intel.com/wbem/wscim/1/amt-schema/1/AMT_GeneralSettings”</p> <p>PS:&gt; Get-CimInstance -ResourceUri $resourceURI -Namespace interop -CimSession $s</p> </td> </tr> </tbody></table> </p> <h3><u></u></h3> <h3><u></u></h3> <h3><u>Goal 3 - Support for down-level OS or non-windows machines</u></h3> <p>CimCmdlets can be used to manage Windows 8, down-level windows machines and any machine that has a CIM standards compliant CIMOM. So, IT pros can now manage non-windows machines with PowerShell in the exact same fashion as they could manage a windows box.</p> <p>To manage these machines, a CimSession to the machine is required. Once a CimSession is created, the machine can be managed irrespective of the operating system. </p> <p>WinRM support on down-level windows machines is limited. The latest WMF-V1 release will enable the latest version of WinRM on the down-level machines; this will help our customers in making best use of these new cmdlets. </p> <p>If customers do not want to install WMF-V1 or do not wish to use WinRM then they can always use DCOM protocol to achieve the same results. </p> <p>&#160;</p> <p> <table style="color: #ffffff" border="1" cellspacing="0" cellpadding="0" width="824" bgcolor="#000066"><tbody> <tr> <td valign="top" width="822"> <p># If ComputerName is specified, WinRM protocol is used</p> <p>PS:&gt; $serverwin8 = New-CimSession –ComputerName &quot;ServerWin8&quot;</p> <p>PS:&gt; $serverwin2k8r2 = New-CimSession –ComputerName “Serverwin2k8r2 &quot;</p> <p># For a remote machine, if you wish to go over DCOM, you need to explicitly specify </p> <p>PS:&gt; $sOpt = New-CimSessionOption –Protocol DCOM</p> <p>PS:&gt; $sessionWin2k8r2Dcom = New-CimSession –ComputerName “Serverwin2k8r2 &quot; –SessionOption $sOpt</p> <p># User Experience remains same irrespective of the target machine.</p> <p>PS:&gt; $instanceServerWin8 = Get-CimInstance –CimSession $ serverwin8</p> <p>PS:&gt; $instanceServerWin2k8r2 = Get-CimInstance –CimSession $ serverwin2k8r2</p> <p>PS:&gt; $instanceServerWin2k8r2DCOM = Get-CimInstance –CimSession $ sessionWin2k8r2Dcom</p> <p>#Note: The results in $instanceServerWin2k8r2 and $instanceServerWin2k8r2DCOM are identical in all aspects. </p> <p># Only the protocol used to get them is different.</p> </td> </tr> </tbody></table> </p> <p>Our objective is to provide the best user experience to all the IT professionals. We would love to know what you think about these new cmdlets. Please give us your comments below.</p> <p>&#160;</p> <p>Vaibhav Chugh</p> <p>SDET, WMI</p> <p>Osama Sajid</p> <p>Program Manager, WMI</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10343415" width="1" height="1"></description><category domain="http://blogs.msdn.com/b/powershell/archive/tags/WMI/">WMI</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/CIM/">CIM</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/MI+Client/">MI Client</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/CimInstance/">CimInstance</category></item><item><title>New-Workflow –MakeItEasy: Authoring Workflows using PowerShell Extended Syntax</title><link>http://blogs.msdn.com/b/powershell/archive/2012/07/21/new-workflow-makeiteasy-authoring-workflows-using-powershell-extended-syntax.aspx</link><pubDate>Sat, 21 Jul 2012 20:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10332271</guid><dc:creator>PowerShell Team</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/powershell/rsscomments.aspx?WeblogPostID=10332271</wfw:commentRss><comments>http://blogs.msdn.com/b/powershell/archive/2012/07/21/new-workflow-makeiteasy-authoring-workflows-using-powershell-extended-syntax.aspx#comments</comments><description><p>Some time back, in his <a href="http://blogs.technet.com/b/windowsserver/archive/2012/05/30/windows-server-2012-powershell-3-0-and-devops-part-2.aspx">blog post</a>, Jeffrey Snover introduced one of the new Windows PowerShell 3.0 feature &ndash; <strong>Windows PowerShell Workflow</strong>. In that post, you saw a glimpse of how to author workflows using PowerShell syntax. This post dives into more details of authoring workflows using PowerShell syntax and various extensions to it.</p>
<h2>Why we chose to extend the PowerShell Language for Workflow Authoring</h2>
<p>As Jeffrey mentioned in that blog post, Windows Workflow Foundation traditionally has been a developer-focused feature that requires Visual Studio and a lot of code to create a solution. To review the solution, another person has to understand XAML or they have to install Workflow Designer. Authoring workflows by using Windows PowerShell is much easier and overcomes the development hurdles. Additionally, you get the benefit of sharing the workflows by simply pasting them into an email or publishing them online.</p>
<p>Another reason, as pointed out in <a href="http://blogs.msdn.com/b/powershell/archive/2012/03/17/when-windows-powershell-met-workflow.aspx">another blog post</a>, is our promise to the PowerShell community about learning once and reusing that knowledge over and over again:</p>
<blockquote>
<p><b><i>&ldquo; &hellip; We respect your investment in learning Windows PowerShell by reusing concepts over and over to make sure learning Windows PowerShell was the best thing you ever did. &hellip;&rdquo;</i></b><b><i></i></b></p>
</blockquote>
<p>While designing the workflow authoring experience, we kept this promise in mind. We also thought of ways to work with existing tools and, hence, came up with two approaches to workflow authoring:</p>
<ol>
<li><b>Script-based Workflow Authoring</b>: Leverage and extend the PowerShell language for workflows so IT Pros can reuse their existing PowerShell scripting skills.</li>
<li><b>XAML-based Workflow Authoring:</b> Plug into the Visual Studio Workflow Designer experience so developers can easily get the management activities in their existing environment and continue leveraging their XAML and Visual Studio knowledge.</li>
</ol>
<p>This post will dive into details of the former approach for workflow authoring: PowerShell script-based workflows. In a later blog post, we will look into the XAML-based authoring experience.</p>
<p>Although there are multiple ways to showcase the new script-based workflow experience, we will explain it by using a real-world example: <span style="text-decoration: underline;">Creating virtual machines on a Hyper-V capable host machine and joining those virtual machines to a domain.</span> This example is a good workflow sample because it has all the necessary workflow characteristics &ndash; long running task across multiple machines that require robustness due to machine reboots.</p>
<p>The benefit of this approach is that by the end of this blog, you will have a real-world workflow sample that can easily be used in your environment. <img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/5661.wlEmoticon_2D00_smile_5F00_438CBD30.png" /></p>
<h2>Workflow Extensions to the PowerShell Language</h2>
<p>In next couple of sections, we will look at various extensions to the PowerShell language that expose and enable Windows Workflow Foundation concepts.</p>
<h3>Workflow Keyword</h3>
<p>The most important of extensions to the PowerShell language is the <b>workflow</b> keyword. To create a workflow, use the <b>workflow</b> keyword, followed by a name for the workflow and, then, followed by the body of the workflow, such as:</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/7536.Invoke_2D00_HelloWorld_5F00_2A59F1EC.png"><img width="255" height="51" title="Invoke-HelloWorld" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Invoke-HelloWorld" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/8625.Invoke_2D00_HelloWorld_5F00_thumb_5F00_5128082C.png" border="0" /></a></p>
<p>As you can see, if you know how to write a PowerShell function, you are 80% on the way to being able to write a workflow.</p>
<p><i>Note: The behavior of a workflow is different than a function and it has a few more rules that we will delve into in another blog post soon.</i></p>
<p>After knowing how easy it is to create a workflow, let&rsquo;s build our workflow for creating virtual machines (VM). We will name it <b>Install-VM</b> &ndash; using a verb-noun name just like those of any other PowerShell command. We will add parameters to our workflow that will specify virtual hard disk (VHD) location for VMs, default prefix for VM name and the number of VM to create.</p>
<p><a name="DefinitionAndParam"></a><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/2211.Install_2D00_VM_2D00_Param_5F00_39244B47.png"><img width="414" height="176" title="Install-VM-Param" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Install-VM-Param" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/0181.Install_2D00_VM_2D00_Param_5F00_thumb_5F00_1FBC480D.png" border="0" /></a></p>
<blockquote>
<p><i>Note: As you might notice, in Windows PowerShell Workflow, you can specify default values for the parameters, just like you do in functions.</i></p>
</blockquote>
<p>In the example above, notice that Windows PowerShell ISE recognizes the workflow and its content and colorizes them appropriately, just like it does for any other PowerShell command.</p>
<h3><a name="ParallelExecution"></a>Parallel Execution</h3>
<p>The underlying Windows Workflow Foundation runtime supports running activities or commands in parallel. We expose this capability in Windows PowerShell Workflow through the <b>parallel</b> keyword, as well as <b>foreach-paralle</b>l, an enhancement to the ForEach statement. With parallel execution, you can significantly reduce the operation time across a set of machines.</p>
<p>Additionally, to execute a collection of activities or commands in order (not in parallel) within a <b>parallel </b>block, use the <b>sequence </b>block, such as:</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/3480.Invoke_2D00_ParallelWorkflow_5F00_1CBF83AF.png"><img width="432" height="250" title="Invoke-ParallelWorkflow" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Invoke-ParallelWorkflow" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/4073.Invoke_2D00_ParallelWorkflow_5F00_thumb_5F00_0E810ABF.png" border="0" /></a></p>
<p>Now let&rsquo;s go back to our <a href="#DefinitionAndParam">previous Install-VM</a> workflow. We'll use a <b>foreach &ndash;parallel </b>block to add logic for creating VMs in parallel.</p>
<p><i><a name="CreateVM"></a><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/0312.Install_2D00_VM_2D00_ForeachParallel_5F00_48237A7A.png"><img width="547" height="310" title="Install-VM-ForeachParallel" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Install-VM-ForeachParallel" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/8814.Install_2D00_VM_2D00_ForeachParallel_5F00_thumb_5F00_195DC1D8.png" border="0" /></a></i></p>
<blockquote>
<p><i>Note: In order to call <b>New-VM</b> and <b>New-VHD</b> commands, you need to install Hyper-V module.</i></p>
</blockquote>
<h3>Checkpoint Workflow Execution</h3>
<p>Windows Workflow Foundation allows a workflow to persist or checkpoint all aspects of its state by using an explicit call to the <b>Persist</b> activity. The same feature is exposed through the <b>Checkpoint-Workflow</b> command in Windows PowerShell Workflow.. With the use of <b>Checkpoint-Workflow,</b> Window PowerShell Workflow checkpoints the workflow state and saves the workflow data to the persistence store. In case of unintended interruptions (machine reboot, process crash, network disruption, etc.), the workflow execution resumes from the last persistence point. Alternatively, to achieve similar results, you can add <b>-PSPersist $true</b> at the end of an activity or command.</p>
<p>Now let&rsquo;s add a <b>Checkpoint-Workflow</b> call to our <a href="#CreateVM">previous Install-VM</a> workflow to save the workflow state.</p>
<p><a name="SaveWorkflowState"></a><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/3225.Install_2D00_VM_2D00_Checkpoint_5F00_6746C189.png"><img width="413" height="160" title="Install-VM-Checkpoint" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Install-VM-Checkpoint" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/3301.Install_2D00_VM_2D00_Checkpoint_5F00_thumb_5F00_0E14D7CA.png" border="0" /></a><i></i></p>
<blockquote>
<p><i>Note: Just look at the <b>param</b> and <b>foreach &ndash;parallel</b> block above and you will notice another cool ISE feature: </i><i>collapsible regions.</i></p>
</blockquote>
<h3><a name="InlineScript"></a>InlineScript: Running Isolated Blocks of Windows PowerShell Script</h3>
<p>By default, each command in a workflow is executed with no PowerShell state sharing. Variables created by one command are not visible to the next command. But, by using the <b>inlineScript</b> keyword it is possible to execute a collection of PowerShell commands as a single execution unit</p>
<p><i><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/2313.Invoke_2D00_InlineScript_5F00_4DDEBE4F.png"><img width="310" height="128" title="Invoke-InlineScript" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Invoke-InlineScript" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/8664.Invoke_2D00_InlineScript_5F00_thumb_5F00_74ACD48F.png" border="0" /></a></i></p>
<blockquote>
<p><i>Note: As mentioned in section 5 of </i><a href="http://blogs.msdn.com/b/powershell/archive/2012/06/19/high-level-architecture-of-windows-powershell-workflow-part-2.aspx"><i>PowerShell Workflow architecture</i></a><i>, for reliability reasons, by default, <b>inlineScript</b> runs in a separate process</i><i></i></p>
</blockquote>
<h3><a name="UsingWithVariables"></a>Accessing Workflow Variables from Different Execution Scopes</h3>
<p>Just like PowerShell remoting in PowerShell 3.0, Windows PowerShell Workflow supports the <b>$Using:&lt;variable name&gt; </b>scope modifier. This new scope modifier can access workflow variables into the context of an <a href="#InlineScript">inlineScript</a>.</p>
<p>Unlike PowerShell, Windows Workflow Foundation does not support dynamic scoping of variables. This means that a variable that is defined in the parent scope cannot be redefined in a child scope. In Windows PowerShell Workflow, to change a workflow-scoped variable from any inner scope, use the <b>$workflow:&lt;variable name&gt; </b>scope modifier.</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/7674.Invoke_2D00_WithUsingandWorkflowScope_5F00_0689685D.png"><img width="600" height="285" title="Invoke-WithUsingandWorkflowScope" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Invoke-WithUsingandWorkflowScope" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/3225.Invoke_2D00_WithUsingandWorkflowScope_5F00_thumb_5F00_7AF3AB1D.png" border="0" /></a></p>
<p>Now, we will use our new <a href="#ParallelExecution">foreach -parallel</a>, <a href="#InlineScript">inlineScript</a> and <a href="#UsingWithVariables">$using</a> concepts, to update our <a href="#SaveWorkflowState">previous Install-VM</a><b> </b>workflow by adding logic for starting the VMs and getting their IP addresses in parallel.</p>
<p><a name="StartVMandWaitForIP"></a><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/4743.Install_2D00_VM_2D00_VMIPAddress_5F00_45B18082.png"><img width="579" height="565" title="Install-VM-VMIPAddress" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Install-VM-VMIPAddress" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/1425.Install_2D00_VM_2D00_VMIPAddress_5F00_thumb_5F00_12E17A0E.png" border="0" /></a></p>
<blockquote>
<p><i>Note: All the commands in workflow have a <b>&ndash;DisplayName</b> common parameter to provide a custom or friendly name for the command. In the previous example, we used it on <b>inlineScript</b>.</i></p>
</blockquote>
<h3>Suspending a Workflow from within the workflow</h3>
<p>Windows PowerShell Workflow has a <b>Suspend-Workflow</b> command that suspends the workflow during its execution. This command gives the workflow author complete control over the workflow suspension behavior independent of the workflow user. For example, a workflow can detect a problem that requires manual intervention, notify the operator of this condition, and then suspend operations until the operator corrects the situation and resumes the workflow.</p>
<p>Let us update our <a href="#StartVMandWaitForIP">previous Install-VM</a><b> </b>workflow to send an email to a senior admin and suspend itself. Once the senior admin gets the email, he/she can resume the workflow manually.</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/5633.Install_2D00_VM_2D00_Suspend_5F00_725A3A5B.png"><img width="660" height="410" title="Install-VM-Suspend" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Install-VM-Suspend" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/8053.Install_2D00_VM_2D00_Suspend_5F00_thumb_5F00_641BC16B.png" border="0" /></a></p>
<p>Additionally, you can integrate the workflow execution with the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh880865(v=vs.85).aspx">Management Odata IIS Extension feature</a> of Windows Server 2012 to manage workflows from any Windows or non-Windows device that can understand HTTP requests. The PowerShell team demonstrated this feature at TechEd North America and TechEd Europe 2012. You can see a recording of this session <a href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/WSV414">here</a> (look at the 1:03:17 mark).</p>
<h3>Workflow Calling Workflow</h3>
<p>This feature of Windows PowerShell Workflow enables you to re-use workflows to create higher-level workflows, while leveraging your existing workflow investment, workflows from other users, and workflows from the PowerShell Community. To use this feature, the child workflow (e.g. <b>Join-Domain</b>) must be defined and imported into the PowerShell session in which the parent workflow is defined..</p>
<p>Let&rsquo;s define a <b>Join-Domain</b> workflow that joins a machine to a domain. To complete the scenario, we will call <b>Join-Domain</b> from our <b>Install-VM </b>workflow.</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/5047.Join_2D00_Domain_5F00_38A092DA.png"><img width="673" height="230" title="Join-Domain" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Join-Domain" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/6102.Join_2D00_Domain_5F00_thumb_5F00_6378F6EC.png" border="0" /></a></p>
<p>Updated <b>Install-VM </b>workflow looks like as follows (and script is attached at the end of the blog post):</p>
<p><i><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/4718.Install_2D00_VM_2D00_WithJoin_2D00_Domain_5F00_182B60EA.png"><img width="692" height="660" title="Install-VM-WithJoin-Domain" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Install-VM-WithJoin-Domain" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/1184.Install_2D00_VM_2D00_WithJoin_2D00_Domain_5F00_thumb_5F00_45404DB8.png" border="0" /></a></i></p>
<blockquote>
<p><i>NOTE: Notice that the param block of <b>Install-VM</b> has two additional parameters: $domainCred and $localCred. The <b>Join-Domain</b> workflow needs these values. </i></p>
</blockquote>
<p>Additionally, you can define nested functions or nested workflows inside the workflows as well, such as:</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/5635.Invoke_2D00_NestedCommand_5F00_7AFA92E7.png"><img width="393" height="270" title="Invoke-NestedCommand" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Invoke-NestedCommand" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/4152.Invoke_2D00_NestedCommand_5F00_thumb_5F00_4FB5FBE0.png" border="0" /></a></p>
<h3>Finding and Running Your Workflow</h3>
<p>As explained by Mir Rosenberg in an <a href="http://blogs.msdn.com/b/powershell/archive/2012/03/17/when-windows-powershell-met-workflow.aspx">earlier blog post</a>, Windows PowerShell Workflows behave just like other Windows PowerShell commands. You can discover them by using <b>Get-Command:</b></p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/7382.Get_2D00_Command_5F00_287BB2AB.png"><img width="585" height="190" title="Get-Command" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Get-Command" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/5314.Get_2D00_Command_5F00_thumb_5F00_410B4FFB.png" border="0" /></a></p>
<p>You can run them interactively or use the <b>AsJob </b>common parameter of workflows to run any workflow as a background job.</p>
<p><b><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/7610.Invoke_2D00_Install_2D00_VM_5F00_182338EC.png"><img width="591" height="32" title="Invoke-Install-VM" style="margin: 0px 0px 0px 30px; border: 0px currentcolor; display: inline; background-image: none;" alt="Invoke-Install-VM" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/3312.Invoke_2D00_Install_2D00_VM_5F00_thumb_5F00_3EF14F2C.png" border="0" /></a></b></p>
<p><b><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/7115.InvokeAsJob_2D00_Install_2D00_VM_5F00_13ACB825.png"><img width="706" height="42" title="InvokeAsJob-Install-VM" style="margin: 0px 0px 0px 30px; display: inline; background-image: none;" alt="InvokeAsJob-Install-VM" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-74-metablogapi/0172.InvokeAsJob_2D00_Install_2D00_VM_5F00_thumb_5F00_3E851C37.png" border="0" /></a></b></p>
<h3>Join-In</h3>
<p>Now that you know how easy it is to author workflows using PowerShell syntax, please try your hand at creating couple of workflows for long-running multi-machine scenarios and tell us about your experience (and feature requests J ). As always, you can send feedback directly to us by using the <a href="http://connect.microsoft.com/powershell">Windows PowerShell Connect site</a>.</p>
<p>While we create our next set of blog posts about Windows PowerShell Workflow, enjoy some additional resources about Windows PowerShell 3.0 and Windows PowerShell Workflow:</p>
<ul>
<li><a href="http://www.windowsitpro.com/blog/powershell-with-a-purpose-blog-36/windows-powershell/powershell-v3-workflow-flagship-feature-140712">PowerShell v3: Workflow is the Flagship Feature</a> (by Don Jones &ndash; PowerShell MVP)</li>
<li><a href="http://halr9000.com/article/947">PowerShell Workflow, Defined</a> (by Hal Rottenberg &ndash; PowerShell MVP)</li>
<li><a href="http://technet.microsoft.com/library/hh847767.aspx">PowerShell Workflow module</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.powershell.workflow(v=VS.85).aspx">PowerShell Workflow SDK documentation</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/hh852738(v=vs.85).aspx">Authoring a Workflow using PowerShell Activities</a></li>
</ul>
<p>Hemant Mahawar [MSFT] <br />Senior Program Manager <br />Windows PowerShell</p>
<p>&nbsp;</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10332271" width="1" height="1"></description><enclosure url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-33-22-71/Install_2D00_VM.psm1" length="5138" type="application/octet-stream" /><category domain="http://blogs.msdn.com/b/powershell/archive/tags/LANGUAGE/">LANGUAGE</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/CMDLET/">CMDLET</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/Get_2D00_Command/">Get-Command</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/PowerShell/">PowerShell</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/Functions/">Functions</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/Workflow/">Workflow</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/PowerShell+Workflow/">PowerShell Workflow</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/Getting+Started/">Getting Started</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/Powershell+3-0/">Powershell 3.0</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/Windows+Server+2012/">Windows Server 2012</category></item><item><title>Windows PowerShell Web Access - Installation guide II</title><link>http://blogs.msdn.com/b/powershell/archive/2012/07/18/windows-powershell-web-access-install.aspx</link><pubDate>Wed, 18 Jul 2012 08:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10330330</guid><dc:creator>PowerShell Team</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/powershell/rsscomments.aspx?WeblogPostID=10330330</wfw:commentRss><comments>http://blogs.msdn.com/b/powershell/archive/2012/07/18/windows-powershell-web-access-install.aspx#comments</comments><description><p><span style="font-size: small; font-family: arial, helvetica, sans-serif;"><span face="Calibri">This blog is a continuation of the post on </span><a href="http://blogs.msdn.com/b/powershell/archive/2012/06/27/windows-powershell-web-access-basic-installation-guide.aspx"><span style="color: #0000ff;" face="Calibri" color="#0000ff">Basic installation guide for PowerShell Web Access</span></a><span face="Calibri">. In the basic installation blog, we configured IIS with the default values used by the Install-PswaWebApplication cmdlet. This is the simplest way to install and configure the feature. </span></span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;" face="Calibri">&nbsp;</span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;" face="Calibri">The video below illustrates two more ways to configure IIS &ndash;</span></p>
<p style="padding-left: 30px;"><span style="font-size: small; font-family: arial, helvetica, sans-serif;"><b><span face="Calibri">1. Using Install-PswaWebApplication</span></b></span></p>
<p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif; font-size: small;" face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp; In this case we specify values for &ndash;WebSiteName and &ndash;WebApplication parameters for the cmdlet</span></p>
<p style="padding-left: 30px;"><span style="font-size: small; font-family: arial, helvetica, sans-serif;"><b><span face="Calibri">2. </span></b><b><span face="Calibri">Using the GUI equivalent</span></b></span></p>
<p style="padding-left: 30px;"><span style="font-family: arial, helvetica, sans-serif; font-size: small;" face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp; In this case, we use IIS Manager to configure the website and the web application pool. <b></b></span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;" face="Calibri">&nbsp;</span></p>
<p><span style="font-size: small; font-family: arial, helvetica, sans-serif;"><span face="Calibri">Detailed instructions on different ways to configure IIS can also be found in the </span><a href="http://technet.microsoft.com/en-us/library/hh831611.aspx#BKMK_config"><span style="color: #0000ff;" face="Calibri" color="#0000ff">Windows PowerShell Web Access help document</span></a><span face="Calibri">. </span></span></p>
<p><span style="font-size: small; font-family: arial, helvetica, sans-serif;"><span face="Calibri">The video also briefly describes how the events are logged for </span><a href="http://blogs.msdn.com/b/powershell/archive/2012/03/07/introducing-windows-powershell-web-access-in-windows-server-8-beta.aspx"><span style="color: #0000ff;" face="Calibri" color="#0000ff">PowerShell Web Access</span></a><span face="Calibri">. Admins can use this information to troubleshoot login failures.</span></span></p>
<script src="http://technet.microsoft.com/en-us/videoembed/installation-guide-it-for-windows-powershell-web-access" type="text/javascript"></script>
<p></p>
<p><span style="font-size: small; font-family: arial, helvetica, sans-serif;">&nbsp;</span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Kriti Jindal</span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Program Manager</span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Windows PowerShell Web Access</span></p>
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Microsoft Corporation</span></p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10330330" width="1" height="1"></description><category domain="http://blogs.msdn.com/b/powershell/archive/tags/Windows+Server/">Windows Server</category><category domain="http://blogs.msdn.com/b/powershell/archive/tags/PowerShell+Web+Access/">PowerShell Web Access</category></item><item><title>Join-Object</title><link>http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx</link><pubDate>Fri, 13 Jul 2012 22:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10329770</guid><dc:creator>PowerShell Team</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/powershell/rsscomments.aspx?WeblogPostID=10329770</wfw:commentRss><comments>http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx#comments</comments><description><h1><span style="color: #000080; font-family: arial,helvetica,sans-serif;">Problem:</span></h1>
<p><span style="font-family: arial,helvetica,sans-serif;">How do I join two lists of objects into a single list? Or the equivalent: How do I join two CSV files into a single one?</span></p>
<p><span style="font-family: arial,helvetica,sans-serif;">Note that joining makes sense only when the two lists or CSV files have something in common.</span></p>
<p>&nbsp;</p>
<h1><span style="color: #000080; font-family: arial,helvetica,sans-serif;">Why do we need Join?</span></h1>
<p><span style="font-family: arial,helvetica,sans-serif;">If </span><span style="font-family: arial,helvetica,sans-serif;">you know why you need join would not enjoy a review of basic database concepts, </span><span style="font-family: arial,helvetica,sans-serif;">feel free to skip this section.</span></p>
<p><span style="font-family: arial,helvetica,sans-serif;">Say </span><span style="font-family: arial,helvetica,sans-serif;">you own a company and want to keep track of the time when your employees </span><span style="font-family: arial,helvetica,sans-serif;">arrive. A simplified table of employees could look like this:</span></p>
<div align="center">
<table style="float: left;" border="0" cellpadding="0">
<tbody>
<tr>
<td width="107" colspan="2">
<p align="center"><span style="font-family: arial,helvetica,sans-serif;"><b>Employee</b></span></p>
</td>
</tr>
<tr>
<td width="30">
<p style="text-align: right;"><span style="font-family: arial,helvetica,sans-serif;"><b>Id</b></span></p>
</td>
<td width="75">
<p><span style="font-family: arial,helvetica,sans-serif;"><b>Name</b></span></p>
</td>
</tr>
<tr>
<td width="30">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">1</span></p>
</td>
<td width="75">
<p><span style="font-family: arial,helvetica,sans-serif;">John</span></p>
</td>
</tr>
<tr>
<td width="30">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">2</span></p>
</td>
<td width="75">
<p><span style="font-family: arial,helvetica,sans-serif;">Mark</span></p>
</td>
</tr>
<tr>
<td width="30">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">3</span></p>
</td>
<td width="75">
<p><span style="font-family: arial,helvetica,sans-serif;">Hanna</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;<span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;">The </span><span style="font-family: arial,helvetica,sans-serif;">id uniquely identifies an employee because two employees can have the same </span><span style="font-family: arial,helvetica,sans-serif;">name. A full table would have more employees. It would also have last name, </span><span style="font-family: arial,helvetica,sans-serif;">first name, the date the employee joined the company, and other columns.</span></p>
<p><span style="font-family: arial,helvetica,sans-serif;">The </span><span style="font-family: arial,helvetica,sans-serif;">Entrance table that contains each employee's arrival time might look like this:</span></p>
<div align="center">
<table style="float: left;" border="0" cellpadding="0">
<tbody>
<tr>
<td width="332" colspan="2">
<p align="center"><span style="font-family: arial,helvetica,sans-serif;"><b>Entrance</b></span></p>
</td>
</tr>
<tr>
<td width="105">
<p style="text-align: right;"><span style="font-family: arial,helvetica,sans-serif;"><b>Employee&nbsp; Id</b></span></p>
</td>
<td width="225">
<p><span style="font-family: arial,helvetica,sans-serif;"><b>When</b></span></p>
</td>
</tr>
<tr>
<td width="105">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">1</span></p>
</td>
<td width="225">
<p><span style="font-family: arial,helvetica,sans-serif;">6/12/2012 08:05:01 AM</span></p>
</td>
</tr>
<tr>
<td width="105">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">1</span></p>
</td>
<td width="225">
<p><span style="font-family: arial,helvetica,sans-serif;">6/13/2012 07:59:12 AM</span></p>
</td>
</tr>
<tr>
<td width="105">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">1</span></p>
</td>
<td width="225">
<p><span style="font-family: arial,helvetica,sans-serif;">6/14/2012 07:49:10 AM</span></p>
</td>
</tr>
<tr>
<td width="105">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">2</span></p>
</td>
<td width="225">
<p><span style="font-family: arial,helvetica,sans-serif;">6/12/2012 10:33:00 AM</span></p>
</td>
</tr>
<tr>
<td width="105">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">2</span></p>
</td>
<td width="225">
<p><span style="font-family: arial,helvetica,sans-serif;">6/13/2012 10:15:00 AM</span></p>
</td>
</tr>
<tr>
<td width="105">
<p align="right"><span style="font-family: arial,helvetica,sans-serif;">44</span></p>
</td>
<td width="225">
<p><span style="font-family: arial,helvetica,sans-serif;">2/29/2012 01:00:00 AM</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>
<p><span style="font-family: arial,helvetica,sans-serif;"></span>&nbsp;</p>