B.T.W. Note the different way to get the form topmost ($form.topmost = $true does not seem to work anymore in Beta3(.1)) but I think this one's better anyway.
I don't know what is new yet, the release notes are the same, I could not find the proposed namechanges e.g.:
· Combine-Path will be renamed to Join-Path · Parse-Path will be renamed to Split-Path · Match-String will be renamed to Select-String · Time-Expression will be renamed to Measure-Command · Write-Object will be renamed to Write-Output
I don't know what is new yet, the release notes are the same, I could not find the proposed namechanges e.g.:
· Combine-Path will be renamed to Join-Path · Parse-Path will be renamed to Split-Path · Match-String will be renamed to Select-String · Time-Expression will be renamed to Measure-Command · Write-Object will be renamed to Write-Output
but to get the full 15 points you need to sort the list, how to do that ? now does MSH have a sort (sort-object) but its not very usefull on this output.
the trick here is to use select-object , with select I came to the following onliner :
# using select to be able to sort to get the 15 points
gc C:\Scripts\Event_7.txt | select {$_.split(",")[0]},@{E={([datetime]"00:$($_.split(',')[1])").add([timespan]"00:$($_.split(',')[2])").tostring('m:ss')};N="t"} | sort -desc t | ft -h
(as no columns where asked, I just renamed the last to make the sort command not to long ;-))
but to get a nice list and because this is a bit cryptic, I also made this version,
# Write it out a litle bit more and rename the first column # so we can show the headers
get-content C:\Scripts\Event_7.txt | select @{Expression={$_.split(",")[0]};Name="Competitor"}, @{Expression={ $Time1 = ([datetime]"00:$($_.split(',')[1])") $Time2 = ([timespan]"00:$($_.split(',')[2])") $Time1.add($Time2).tostring('m:ss') };Name="Time"} | sort -property Time -descending :$($_.split(',')[1])").add([timespan]"00:$($_.split(',')[2])").tostring('m:ss')};N="t"} | sort -desc t | ft -h
*Note* technicaly this is still a one-liner I just entered some linebreaks and spaces to format it a bit.
this will add meaningfull descriptions to the table generated. the naming and formating af data in select is not yet in the Help but tor more information see also the good explanation in ::MSH:: from DontBotherMeWith Spam about the first MP3 entry on my blog where I use this also.
$SQL = "SELECT MedalWinners.Country," $SQL += " Sum(MedalWinners.Gold) AS Gold," $SQL += " Sum(MedalWinners.Silver) AS Silver," $SQL += " Sum(MedalWinners.Bronze) AS Bronze," $SQL += " Sum([Gold]+[silver]+[bronze]) AS Total" $SQL += " FROM MedalWinners GROUP BY MedalWinners.Country" $SQL += " ORDER BY Sum([Gold]+[silver]+[bronze]) DESC;"
And the SQL query I did just create in Access, only I changed the Query by removing the Sum that Access does append automatic so I do not have to make the headers myself as the scripting guys did ;-)
So to make it a bit more an event I made a second version that just gets the original table and does the processing of the data on the MSH side.
$dt | select -unique country | select country, @{e={$dt.compute("Sum(Bronze)","Country = '$($_.country)'")};n='Bronze'}, @{e={$dt.compute("Sum(Silver)","Country = '$($_.country)'")};n='Silver'}, @{e={$dt.compute("Sum(Gold)","Country = '$($_.country)'")};n='Gold'}, @{e={$dt.compute("Sum(Total)","Country = '$($_.country)'")};n='Total'} | sort Total -desc | ft -auto
You can see that it just append a column for the type Int, and adds a expression to it. Then I do a select -unique to get only the countries while I loop through them I use the Compute Method of the datatable, that takes a Expression and a filter as arguments, to sum the medals for every country , like in the first sample I did this all within a Select statement inside calculated properties.
$words | select @{e={$_};n='Word'},@{e={$found -contains $_};n='Found'} | sort found -desc | ft -auto
that was it for this final day, hoped you liked this series as I did doing the original Games and the MSH side-o-lypics series and thanks from here to the scripting guys for aranging the Scripting games, and hope there will be some MSH events in it next year.
Enjoy,
Greetings /\/\o\/\/
PS you can find the needed files and orignal events from the main pa Tags : Monadmsh
and the solutions or another 2 events of the The 2006 Winter Scripting Games are in : and again, I did the answers in MSH also,.... and Yes one-liners ;-)
Event 3 The Quadratic Quest
Origial answer :
a = Wscript.Arguments.Item(0) b = Wscript.Arguments.Item(1) c = Wscript.Arguments.Item(2)
numAnswer1 = ((-1 * b) + (Sqr((b^2) - 4 * a * c))) / (2 * a) Wscript.Echo numAnswer1
numAnswer2 = ((-1 * b) - (Sqr((b^2) - 4 * a * c))) / (2 * a) Wscript.Echo numAnswer2
Cool or not ?, we just cast the get-content of the file to a string, and just call his methods.
the result is like this :
MSH>type C:\Scripts\Event_4.txt
The Scripting Gusy are pleased to announce the 2006 Winter Scripting Games to be held February 13-24 at the TechNet Script Center. This event is sponsored by the Microsoft Scripting Gusy.
THE SCRIPTING GUYS ARE PLEASED TO ANNOUNCE THE 2006 WINTER SCRIPTING GAMES TO BE HELD FEBRUARY 13-24 AT THE TECHNET SCRIPT CENTER. THIS EVENT IS SPONSORED BY THE MICROSOFT SCRIPTING GUYS.
the next events will be bit harder to put one one line (at reast readable ;-), as we have the ";" ) but still I think they will be to do on MSH also.
so you can load it and get advanced lineediting capabilities, sounds real cool !.
I did not try it before, as I was first getting used to MSH in the "normal" console (familuar ;-) As I 'm busy on my own "Hosting project", I just wanted to give it a look, when I did see the post about lemonade, as it is not posted yet, I I downloaded but jaMSH I could not get itinstalled on beta 3.
as I said before (Monad hosting )I waited for this post as I was fighting with access to host objects, but I was looking in the wrong direction (passing assembly), I will go on with Lee's example more about that later.
Also I liked this series because it did remember me about those old school day's.
Great work Lee !
Next, I did see a lot of posts on the Monad team blog,
also so good monad examples on Keith Hill's Blog in : MSH: If "Scheme is Love" and "Lisp is Sin", then MSH must be what - "a promising first date"? MSH: Analyzing Visual C# Project Files
I'm sure I missed some, and someI should have mentioned but forget where to find. but I hope this list is usefull, I think this a bunch of good info about Monad, sorry, for the ones I missed.
On the 4th day of the scripting games , I got the 100 score :-), as I posted the last script on the second day, I was a bit worried ;-)
also dr Scripto posted the Dr. Scripto Concentration Game, I decided to redo this in MSH , you can find the script below, but you need the Pictures of the original sample in the scripts directory (or change the script for other picures)
# Concentration.msh # a remake in MSH of Dr. Scripto Concentration # You need the pictures of the HTA version # # /\/\o\/\/ 2006 # htpp://mow001.blogspot.com
the games are realy nice to do (even in VBscript), also to remember how handy MSH would be to do the same,
as MSH is not a Official Script games language yet (I hope we will be allowed in next games), I will do some of the events the monad way here , as the answers of the first event are posted on the Scripting Games page I will do some of those scipts here in MSH (complete scripts): to follow them (see the original script and explanations ) you can check the Answer: Scriptathalon
Ok, I needed 3 lines for the last one (could only find a reverse function on the array type) , but the rest of the scripts not fixed with one line, but replaced by one line.
I tryed to get access from the hosted MSH to the form that hosted it, I did this :
I had the problem as mentioned in page [0], after reading page [4], and today allready readed this : MSH Logo – A GUI Disaster, I decided ok I wait for another post, so did [Q]
but I liked the search, I only typed a small bit and I did not need the mouse all this ;-)
and for example this post on the Monad team blog :Days till Xmas and the comments and you could also use AddSeconds etc. methods or the Substract method(you need a cast then).
so it depents on the situation, also I'm still trying to find out a bit of a standard way to do things for myself, you can already see I do things different since my first posts, as I get more used to MSH. I still have to develop a more "standard" coding habit for production scripts, but as we are still in beta, I like to find different way's.
no MSH there yet I think, but still think I'm in. maybe see you there.
gr /\/\o\/\/
PS there are some community scripts added to the community script center already also, but did not see MSH ones with them, I hope they will come soon, if you wanna help see this post. First Monad B3 impression and please help the scripting guys
We got an Application ID, Generated the DLL to reference in MSH, and generated A Web search Object from MSH, and did your first Search with it.
(If you do not have the DLL or AppID you cannot run the Script, see Part 1 on how to make them) We will build upon this by making a function Using the MSN Search Objects,
as said in last post there where 2 thing I would like it to do, let me go to the Next results and Making the Links Usefull,
To do this I had to ask the user for input, I decided to use the $host.ui.PromptForChoice() Method for this.
this is the Same as used by the CMDlets, so it is constistent and also provides a Help system.
I build it up to take N for Next, Q to Quit and the numbers 0-9 to select the links from the results.
The Choices now look like this :
Choice Press Number to Start Page, Q to Quit [0] 0 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [N] Next [Q] Quit [?] Help (default is "N"): ? 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - N - Next 10 Q - Quit [0] 0 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [N] Next [Q] Quit [?] Help (default is "N"):
after that I check the choices made,
for the Next I needed to get the Next results, this is very easy by setting the Offset of the SourceRequest, and doing the search again.
then I Needed a way to open a link from the results, I just use the Number returned from the $choice if it was not Next or Quit, to get the URL and use the Shell.Application COM Object to start it.
Also I added a bit of Color to make it easier to read.
with this done, we can do a Paged MSN search from MSH, just by typing search-MSH and the test to search, you get 10 pages at a time, and you can start them by typeing there number.
the function is still a bit RAW (e.g. It will open explorer in you current folder as you choose a non existing link, and you can't browse back for example) but I think its allready very handy for a Quick Search from MSH.
Function Prompt-Continue ($Caption = "Choice", $Message = "Press Number to Start Page, N or Enter for next page, Q to Quit",$choices = $cl){ $Choice = $host.ui.PromptForChoice($caption,$Message,[System.Management.Automation.Host.ChoiceDescription[]]$choices,10) return $Choice }
# build-Up MSN Search Service Object
$MSN = new MSNSearchService
$s = new SourceRequest $s.source = [sourcetype]::web $s.ResultFields = ([ResultFieldMask]::All)
$sr = new SearchRequest $sr.AppID = "YOUR AppID HERE !!!!!!!" $sr.Requests = $S $sr.Flags = [SearchFlags]::None $sr.CultureInfo = "en-US"
Then we need to "Import" the MSNSearch Web Reference.
this involves 3 steps :
to do this we First use wsdl.exe (Microsoft Web Services Description Language Utility) from VS2005 or the SDK.
MSH>& 'C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\wsdl.exe' http://soap.search.msn.com/webservices.asmx?wsdl
Microsoft (R) Web Services Description Language Utility [Microsoft (R) .NET Framework, Version 2.0.50727.42] Copyright (C) Microsoft Corporation. All rights reserved. Writing file 'C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\MSNSearchService.cs'.
This generates a C# file that we compile in step 2 :
Title : /\/\o\/\/ on MSH (Monad) Description : win32_quotaevent I used Get-WmiClasses from Wmi-Help Part 1 , to list them (we installed nothing more on the R2 server as FSR M) (its easy to use this script remote by filling in the Path in the ... Url : http://mow001.blogspot.com/
Title : /\/\o\/\/ on MSH (Monad): Watching FSRM Quota and filescreen events ... Description : win32_quotaevent I used Get-WmiClasses from Wmi-Help Part 1 , to list them (we installed nothing more on the R2 server as FSR M) (its easy to use this script remote by filling in the Path in the ... Url : http://mow001.blogspot.com/2006/01/watching-fsrm-quota-and-filescreen.html
From here on you can just change the Query, and search again.