/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Moving to ThePowerShellGuy.com "," PowerShell Code formatting test for my new Blog "," PowerShell Code formatting test for my new Blog "," PowerShell Community Extensions V1.0 "," PowerShell : Access remote eventlogs "," Windows PowerShell Scripting Sweepstakes! "," PowerShell : making Custum Enums "," TechNet Webcast: An Overview of Windows PowerShell... "," "Windows PowerShell: TFM" goes "Gold" "," PowerShell : Advanced renaming of files "," ")

Tuesday, February 28, 2006


out-dataGrid function for Monad

This function will translate the input it gets from the pipeline to a dataTable and then shows it on a Form in a datagrid.

some examples to try :

ls | out-datagrid
gps | out-datagrid

ls function: select name,definition | out-datagrid
get-alias | out-datagrid
get-command | select name,definition | out-datagrid
get-help about_* | select name,synopsis | out-datagrid

get-wmiobject win32_share | select [a-z]* | out-datagrid


the Funtion looks like this :

# Function out-datagrid
# shows piplineinput in datagrid
# /\/\o\/\/ 2006
# http:mow001.blogspot.com

Function out-dataGrid {

  # Make DataTable from Input

  $dt = new Data.datatable
  $First = $true
  foreach ($item in $input){
    $DR = $DT.NewRow()
    $Item.mshObject.get_properties() | foreach {
      If ($first) {
        $Col =  new-object Data.DataColumn
        $Col.ColumnName = $_.Name.ToString()
        $DT.Columns.Add($Col)       }
      if ($_.value -eq $null) {
        $DR.Item($_.Name) = "[empty]"
      ElseIf ($_.IsArray) {
        $DR.Item($_.Name) =[string]::Join($_.value ,";")
      Else {
        $DR.Item($_.Name) = $_.value
    $First = $false

  # show Datatable in Form 

  $form = new-object Windows.Forms.form 
  $form.Size = new-object System.Drawing.Size @(1000,600
  $DG = new-object windows.forms.DataGrid
  $DG.CaptionText = "Number of Rows $($DT.rows.Count)" 
  $DG.AllowSorting = $True 
  $DG.DataSource = $DT.mshobject.baseobject 
  $DG.Dock = [System.Windows.Forms.DockStyle]::Fill 
  $form.text = "$($myinvocation.line)" 

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.


Greetings /\/\o\/\/
Tags :

 5 comments links to this post

Monday, February 27, 2006


Windows "Monad" Shell (MSH) Beta 3.1

There is a new Monad beta,

Windows "Monad" Shell Beta 3.1 (for .NET Framework 2.0 RTM) x86 http://www.microsoft.com/downloads/details.aspx?FamilyID=239a1116-c0f5-4320-84fc-2ad625ebb910&DisplayLang=en4

Windows "Monad" Shell Beta 3.1 (for .NET Framework 2.0 RTM) AMD64 http://www.microsoft.com/downloads/details.aspx?FamilyID=24bace7a-253a-4794-bb4f-d92715cb0a68&DisplayLang=en4

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 If I find out more I will let you know,

thanks to Jean for posting the links in the NG

gr /\/\o\/\/

Tags :

posted by /\/\o\/\/
 1 comments links to this post

Windows "Monad" Shell (MSH) Beta 3.1

There is a new Monad beta,

Windows "Monad" Shell Beta 3.1 (for .NET Framework 2.0 RTM) x86 http://www.microsoft.com/downloads/details.aspx?FamilyID=239a1116-c0f5-4320-84fc-2ad625ebb910&DisplayLang=en4

Windows "Monad" Shell Beta 3.1 (for .NET Framework 2.0 RTM) AMD64 http://www.microsoft.com/downloads/details.aspx?FamilyID=24bace7a-253a-4794-bb4f-d92715cb0a68&DisplayLang=en4

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 If I find out more I will let you know,

thanks to Jean for posting the links in the NG

gr /\/\o\/\/

Tags :

posted by /\/\o\/\/
 0 comments links to this post

Friday, February 24, 2006


scripting games Last Day MSH answers for event 7 and 8

The Final day of the scripting games,

Anwers to Event 7 and Event 8 are posted on the Scripting Games Home. (where you can also find the needed files and original events)

And I will post the MSH versions I made as aswers here, lets start with event 7.

Event 7

In my Vbscript answer I used this way to translate the time,

Total = (TimeValue("00:" & time1) + TimeValue("00:" & time2))

for the rest my script was basicly the same.

with the same construction in MSH I came to this one-liner for the 10 points answer :

# 10 Points one-liner unsorted

gc C:\Scripts\Event_7.txt | foreach {$l = $_.split(",");"$($l[0];(([datetime]`"00:$($l[1])`").Add([timespan]`"00:$($l[2])`")).tostring('m:ss'))"}

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"},
       $Time1 = ([datetime]"00:$($_.split(',')[1])")
       $Time2 = ([timespan]"00:$($_.split(',')[2])")
  };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.

for another even more powerfull way to do this kind of things (and more) in MSH (with add-member) see the second post about MP's Some fun With Monads Add-Member, MP3 files and COM

But time to go on to the last event

Event 8

For this I also made 2 solutions,

The first one is basicly the same as the Vbscript version.

- It connects to access,
- It does transform the data in the SQL query
- It outputs the data.

# Open connection to the Access DataBase

$mdb = "c:\scripts\event_8.mdb"
$ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$mdb"
$Conn = new-object System.Data.OleDb.OleDbConnection($connString)

# do processing in SQL Query 

$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;" 

$cmd = new-object System.Data.OleDb.OleDbCommand($SQL,$Conn)
$da = new-object System.Data.OleDb.OleDbDataAdapter($cmd)
$dt = new-object System.Data.dataTable

$dt | ft -auto

You can see the formatting part is a bit easier (I used the spaces function in my VbScript answer), for the rest is basicly the same.
also I did the datebase connection already for Excel, see Using ADO to get data from Excel to Dataset in Monad. and SQL see Getting and Working With SQL Server data in Monad

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.

this second version looks like this :

# Alternative way, do the processing on MSH side 

$mdb = "c:\scripts\event_8.mdb"
$ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=$mdb"
$Conn = new-object System.Data.OleDb.OleDbConnection($connString)

$cmd = new-object System.Data.OleDb.OleDbCommand("select * from medalwinners",$Conn)
$da = new-object System.Data.OleDb.OleDbDataAdapter($cmd)
$dt = new-object System.Data.dataTable 

$Total = $dt.Columns.add("Total",[int])
$Total.expression = "(Gold+silver+bronze)"

$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.

and then as promised, as a bonus, the alternative ending for The Scripting Games Event 6 in MSH
as you can guess by now it uses SELECT ;-)

# Format and output results 

$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.


Greetings /\/\o\/\/

PS you can find the needed files and orignal events from the main pa
Tags :

posted by /\/\o\/\/
 11 comments links to this post

Thursday, February 23, 2006


Scripting Games almost over

On this rest day, the article Don’t Worry, Get SAPI, is posted on the scripting guys site.

I will keep it short today, the rest is up-to-you

(new-object -com SAPI.SpVoice).speak((get-date)),

this Lets Monad say the date for you

Tomorrow a bigger post with the MSH solutions for the Events 7 and 8,

for both I have 2 solutions in MSH, and another last line for Event 6 (as of it is not edited enough ;-))

I think the scripts posted tomorrow will make real nice examples of the power of Monad,

Greetings /\/\o\/\/

Tags :

posted by /\/\o\/\/
 6 comments links to this post

Wednesday, February 22, 2006


The Scripting Games Event 6 in MSH

And up for the answer to Event 6 but then in MSH

Event 6 is the Word Search Slalom ,
I liked this one, thas solves a Word Square.

I did skip event 6 for here as it's excel and not much different,

I will do the 15 points option, finding the words horizontal and vertical in the wordsquare.

The script looks like this :


# Get Text

$text = gc C:\scripts\event_6b.txt

# reverse the text

$textR = $text | foreach {$a = $_.ToCharArray();[array]::reverse($a);[string]::join("",$a)}

# Get Vertical Text 

$textV = [string]::join("",(0..($text[0].length - 1) | foreach {$i=$_;$text | foreach {$_[$i]}}))

# reverse the vertical text

$VR = $V | foreach {$a = $_.ToCharArray();[array]::reverse($a);[string]::join("",$a)}

# find the words 

$found = @()
$words | foreach {if ($VR -match $_){$found += $_}}
$words | foreach {if ($text -match $_){$found += $_}}
$words | foreach {if ($textR -match $_){$found += $_}}
$words | foreach {if ($textV -match $_){$found += $_}}

# output results

$words | foreach {"$_ = $($found -contains $_)"}


after a comment from DontBotherMeWithSpam (thanks),
I came up with this replacement for the Find words section :

# find the words  

foreach ($word in $words){$Text,$textR,$textV,$vr | foreach {if($_ -match $word){$found += $word}}}

Fixed a naming typo in the origional script and the textV line is cleaned up.

$found = @()

# Arrange text 

$text = gc C:\scripts\event_6b.txt
$textR = $text | foreach {$a = $_.ToCharArray();[array]::reverse($a);[string]::join("",$a)}
$textV = [string]::join("",(0..($text[0].length - 1) | foreach {Foreach ($line in $text){$Line[$_]}}))
$textVR = $textV | foreach {$a = $_.ToCharArray();[array]::reverse($a);[string]::join("",$a)}

# find the words 

foreach ($word in $words){$Text,$textR,$textV,$textVR | foreach {if($_ -match $word){$found += $word}}}

# output results

$words | foreach {"$_ = $($found -contains $_)"}


Greetings /\/\o\/\/
Tags :

PS In 2 day's with Event 7's solution I will post I nice replacement for the last line.

posted by /\/\o\/\/
 6 comments links to this post

Monday, February 20, 2006


Scripting Games week 2

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

and the MSH answer is :

function QQ ($a,$b,$c) {$d = [math]::Sqrt([math]::Pow($b,2) - 4 * $a * $c);(-$b + $d) / (2*$a);(-$b - $d) / (2*$a)}

MSH>qq 2 -4 -6

and this one I like even more,

Event 4: Text File Tug-of-War

Original answer :

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Event_4.txt", ForReading)

strContents = objFile.ReadAll

strContents = Replace(strContents, "Gusy""Guys")
strContents = Replace(strContents, vbCrLf, " ")
strContents = UCase(strContents)

Set objFile = objFSO.OpenTextFile("C:\Scripts\Event_4.txt", ForWriting)
objFile.Write strContents

and the MSH answer is:

"$(gc C:\Scripts\Event_4.txt)".toUpper().replace('GUSY','GUYS') | out-file C:\Scripts\Event_4.txt

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.

MSH>"$(gc C:\Scripts\Event_4.txt)".toUpper().replace('GUSY','GUYS') | out-file C:\Scripts\Event_4.txt

MSH>type C:\Scripts\Event_4.txt


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.

keep you posted ;-)

gr /\/\o\/\/
Tags :

posted by /\/\o\/\/
 7 comments links to this post

Friday, February 17, 2006


Monad Links

As Beta 3 arrived the Monad activity on the web gets more and,
I will link some, I did see and think are nice,

Line Editing in MSH,

The alternate Monad shell jaMSH “Jeff’s Alternative Monad SHell”, is becoming a Snapin :
See : jaMSH is no more. Long live lemonade

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.

talking about hosting MSH,

Lee posted, the final MSH logo version, very cool.
see : MSH Logo – allowing users to extend its functionality

Also try the Examples !!

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,

today about the Names enforcement :
Monad breaking change announcement: Approved verb names enforcement.
(last chance to vote ;-)

Write-Progress, with a link to Tony's blog ( MSH for fun) using a biology web service.
he is also doing a great series about security next to the ACL entrys I metioned before :

group membership :
Groups Command in MSH: Get-WindowsIdentity cmdlet
a very cool one about getting Owners of processes
Add-ProcessOwner cmdlet (update)
Credentials :
A Clone of id/whoami in MSH
Survival as a Non-Administrator: A Monad view
Tired of Typing Administrator’s Password Repeatedly?
and Lee's additions
Caching credentials for administrative tasks

and some more on the Monad Team blog:

Using and finding .NET Objects in MSH : .NET types
Very nice article with a lot of good tips : Finding which parameters are used the most

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

and a whole series about Snap-in's
Adding help for cmdlets in a MshSnapIn (this is only the last one you will find some more here)

then, the next one,

Printing and scaling an Image in Monad
A very cool printing example by DBMWS on MonadBlog
"[MSH] Clipboard Snapin..."

On the LazyAdmin.com some posts about amongs others WMI / Profiles / get-history
MSH (Monad) (6)

Exchange : on Glen's Exchange Dev Blog :
Oversize mail reporting with Monad

also interesting :

Mentioned befor but now complete series about Monad in computerworld :
Hands On: Learning Monad, the scripting language for Windows Vista

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.


greetings /\/\o\/\/
Tags :

PS *edit * Blogger was gone for a long time as I tryed to post this,
some more as an hour I was sweating , but it did survive pfff

I need to get into RSS publishing sometime, to do this offline, as this blogger interface gives me to much problems.

posted by /\/\o\/\/
 0 comments links to this post

MSH Concentration (scripting games part 4)

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)


Greetings /\/\o\/\/
Tags :

# Concentration.msh 
# a remake in MSH of Dr. Scripto Concentration
# You need the pictures of the HTA version
# /\/\o\/\/ 2006 
# htpp://mow001.blogspot.com


$Imagepath = parse-path $MyInvocation.mycommand.path
$rows = 4
$Cols = 4

# Build Form 

$form = new-object System.Windows.Forms.form
$Form.text = "MSH Concentration by /\/\o\/\/"

$form.width = ($rows * 55) + 20
$form.Height = ($Cols * 55) + 70 

# Build Menu 

$MS = new-object System.Windows.Forms.MenuStrip
$Mi = new-object System.Windows.Forms.ToolStripMenuItem("&File")

$Msi1 = new-object System.Windows.Forms.ToolStripMenuItem("&New")  

$Msi2 = new-object System.Windows.Forms.ToolStripMenuItem("&Quit")


# Add a MenuLabel for the score

$ml = new-object System.Windows.Forms.ToolStripLabel

# Add menu to form 


# Make Imagelist

$images = @()
1..8 | foreach { 
         $image = [Drawing.Image]::FromFile("$Imagepath\Scripto_$_.gif")
         $image.tag = $_  
         $images += $image
         $images += $image 

# function to handle ButtonClick

Function OnClick {
  $num = $args[0]
  if ($map[$num].image -eq $null -and $clicks -lt 3) {

    $script:clicks += 1
    $map[$num].image = $images[$num]

    if ($clicks -eq 1) {
      $script:sav = $num

    if ($clicks -eq 2) {
      if ($images[$num].tag -eq $images[$script:sav].tag) {
        $map[$num].enabled = $false
        $map[$script:sav].enabled = $false

      } Else {
        sleep 1
        $map[$num].image = $null
        $map[$script:sav].image = $null
      $script:clicks = 0  
      $script:pairs += 1
      $ml.text = "Total Pairs Clicked : $pairs"

# Create the PlayField (array of Buttons)

$Button = new-object System.Windows.Forms.Button
[System.Windows.Forms.Control[]]$Map = @()
for ($i = 0;$i -lt $rows;$i++) 
  $row = @()
  for ($j = 0;$j -lt $Cols;$j++) 
    $Button = new-object System.Windows.Forms.Button
    $Button.width = 55
    $Button.Height = 55
    $button.top = ($i * 55) + 25
    $button.Left = $j * 55
    $button.Name = ($i * $cols) + $j
      [int]$num = $this.name
      OnClick $num 
    $button.font = new-object system.drawing.font('Microsoft Sans Serif',10,'bold')
    $Row += $Button
  $Map += $row

# Function to start a new game 

function new-game {
  $ml.text = "A new Game has Just started"
  $script:clicks = 0
  $script:pairs = 0
  $script:sav = 0

  # Randomize Imagelist

  $R = new-object system.random
  0..15 | foreach {
            $map[$_].image = $null
            $map[$_].enabled = $true
            $rndNum = $R.next(1,17) - 1
            $tmp = ($images[$_])
            $images[$_] = ($images[$rndNum])
            $images[$rndNum] = $tmp


# hit the Road 

. new-game
$form.topmost = $true 

posted by /\/\o\/\/
 0 comments links to this post

Thursday, February 16, 2006


scripting games part 3

No answer on this event yet,
but as this is only debugging, I think I could do this one already in one line ;-)

Debugging Dash

get-wmiobject Win32_NetworkAdapterConfiguration -filter "IPEnabled ='True'" | fl Caption,DHCPEnabled,IPAddress

Caption : [00000001] Intel(R) PRO/1000 CT Network Connection
DHCPEnabled : True
IPAddress : {}

gr /\/\o\/\/
Tags :

posted by /\/\o\/\/
 0 comments links to this post

Wednesday, February 15, 2006


2006 Winter Scripting Games (part 2)

I'v been a bit busy this week,As I prepared for my first Monad presention I did at work today,
and did join the 2006 Winter Scripting Games – February 13 - 24 as I mentioned earlier.

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

Question 1.

("Sunday", "Monday", "Sundae", "Tuesday", "Sunshine") -match "sun"


Question 2.



Question 3.

$values = 1, 2, 3, 4 ,5, 6, 7, 8, 9
for ($i=0 ; $i -lt $values.Length ; $i+=2) {$values[$i]}


Question 4.



Question 5.


66 %

Ok, this could take some extra explaining for some help on this one see :

Question 6

("A", "B", "C", "D", "E") foreach {[int][char]$_}


Question 7.

(8, 9, 10, 11, 12) foreach {$_.tostring("x")}

(see question 5 )

Question 8.

[string]::join(" ",("A","B","C","D","E"))


Question 9.

$Command = '$a = 1' + "`n"
$Command += '$b = 2' + "`n"
$Command += '$a+$b'

invoke-command $Command


Question 10.

$string = "This is a test string."

$a = $string.ToCharArray()

.gnirts tset a si sihT

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.

gr /\/\o\/\/
Tags :

posted by /\/\o\/\/
 1 comments links to this post

Wednesday, February 08, 2006


Monad hosting

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 ;-)

To do this you need :

Search with MSNSearch Web API from MSH (Part 1) ,
Search with MSNSearch Web API from MSH (Part 2) ,
Check spelling with MSN Search from MSH (Part 3) (some fixes on 2 also)

I will fix the counter and some other things in part 4 ;-)

gr /\/\o\/\/
Tags :

posted by /\/\o\/\/
 0 comments links to this post

Get current user in Monad

as anwer to my question in last post,
how many ways can you find to get the current user from MSH,

I came up with this list : *Edit* - repost WITH pipelines

# environment variable


gc env:username

ls env:\username

gci env: -inc username

# registry

(gp "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\").'Logon User Name'

gp "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\" | fl 'Logon User Name'

gi "hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\" | gp | select 'Logon User Name'

# .NET







(new -com WScript.NetWork).username

(new -com WScript.Shell).Environment('process').item('username')

(new -com WScript.Shell).ExpandEnvironmentStrings("%username%")


get-wmiobject Win32_ComputerSystem | fl UserName

(get-wmiobject Win32_ComputerSystem).UserName

feel free to add more :-)

gr /\/\o\/\/
Tags :

posted by /\/\o\/\/
 1 comments links to this post

Tuesday, February 07, 2006


Different ways to do things in Monad, and some links

There are often a lot of way's to do things in Monad :
for example see this thread in the newsgroup :

last character of the last line is a newline?

I posted this oneliner :

"updates : $($items foreach {$_;'`n'})"

but in a script I would more likely like something like this :

$sb = new Text.StringBuilder
$sb = $sb.Append("Updates :`n")
$ident = " " * ($sb.Capacity / 2)

foreach ($update in $updates)
$sb = $sb.Append("$Ident $Update`n")

if I needed to output date for a report etc, where I could not use just the format commands in MSH.

for another example of the stringbuilder, I use it to create the WMI scripts generated by get-WmiMethodhelp here : MSH get-WmiMethodHelp (GWM) Update + format tips.
I use $sb = $sb since : erroraction on new-item, my Wrong use of Stringbuilder (b.t.w. it was not "wrong" only different)

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.

another post in the Monad team blog, I would recomment reading is this one :
Finding which parameters are used the most, there are some very handy tricks in there.

and also on the Monad team blog Some CMDlets going to change there name :
Monad cmdlet cleanup update
(so some more things to do different)

also I nice trick I found here , [Monad][Windows]今日の Monad 離れ業
I could not read it but I liked this command :

get-member -InputObject (get-childitem -?) where {$_.MemberType -eq "NoteProperty"}

so this would be a way to list all the examples :

(get-command foreach {(&$_.name -?).examples})

again for a different version of this I did before : Read the raw Monad XML helpfiles
(and a different one still to come ;-) )

and to end this post, an exercise for you : (stolen from Eric and JS, to get comments ;-) )

how many way's you can find to list the current username ?
I did find a lot of them :-)

Tip, you can find a couple in my blog, but there are more to find.


gr /\/\o\/\/
Tags :

posted by /\/\o\/\/
 2 comments links to this post

Sunday, February 05, 2006


2006 Winter Scripting Games

The scripting guys are organising, the

2006 Winter Scripting Games – February 13 - 24

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

posted by /\/\o\/\/
 0 comments links to this post

Friday, February 03, 2006


Check spelling with MSN Search from MSH (Part 3)

A small word checker for MSH using MSN Search,

it uses the Culture of the MSH Shell, but you can overrule it.
it works like this :

MSH>check-spelling januar
MSH>check-spelling januar nl-nl

the script looks like this :

# Check-Spelling 
# checks spelling of a word using MSN Search Web Service   
# /\/\o\/\/ 2006  
# http://mow001.blogspot.com 

Function Check-Spelling {
        [string]$Culture = (get-Culture).name
  $MSN = new MSNSearchService

  $s = new SourceRequest
  $s.source = [sourcetype]::spelling
  $s.ResultFields = ([ResultFieldMask]::All)

  $sr = new SearchRequest
  $sr.AppID = "Your AppID here !!!!!"
  $sr.Requests = $S
  $sr.Flags = [SearchFlags]::None
  $sr.CultureInfo = $Culture
  $sr.query = $word

  $r = new sourceResponse
  $r = $MSN.Search($sr)
  $r.responses[0].results | foreach {$_.Title}

(for getting the DLL and AppID Needed see, Search with MSN Search Web API from MSH (Part 1))

gr /\/\o\/\/
Tags :

PS I'm also working on extending the search example of the 2nd part of this series,
for now 2 quick fixes I did I thinks are handy :

# fixes on example part 2

# Overrule the Prompt to show result Count (I did rename prompt-continue) :

    $Choice = Prompt-Choice -caption "Showing : $($S.Offset) to $($S.Offset + 9) of $($r.Responses[0].total) Results"

# Fix for opening explorer on empty URL
   [0-9] {
           if ($r.responses[0].results[($_)].url) {
             (new-object -com shell.application).ShellExecute($r.responses[0].results[($_)].url)

posted by /\/\o\/\/
 1 comments links to this post

Thursday, February 02, 2006


Search with MSNSearch Web API from MSH (Part 2)

In this second posting about the MSN Search Web Service from MSH,
in last post Search with MSNSearch Web API from MSH (Part 1) ,

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 :

Press Number to Start Page, Q to Quit
[00  [11  [22  [33  [44  [55  [66  [77  [88  [99  [N] Next  [Q] Quit  [?] Help (default is "N"): ?
0 -
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
N - Next 10
Q - Quit
[00  [11  [22  [33  [44  [55  [66  [77  [88  [99  [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.


gr /\/\o\/\/
Tags :

# Search-MSH 
# MSN Web search Function, using Web API  
# /\/\o\/\/ 2006 
# http://mow001.blogspot.com 

set-Alias new = new-object
Function Search-MSN {

  # Build Choices Menu

  $Next = ([System.Management.Automation.Host.ChoiceDescription]"&Next")
  $Next.helpmessage = "Next 10"

  $Quit = ([System.Management.Automation.Host.ChoiceDescription]"&Quit")
  $Quit.helpmessage = "Quit"

  $Start = [System.Management.Automation.Host.ChoiceDescription[]]("&0","&1","&2","&3","&4","&5","&6","&7","&8","&9")

  $Cl = $start  
  $cl += ($Next,$Quit)

  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"

  # Do Inital Search
  $sr.query = "$args"
  $r = new sourceResponse
  $r = $MSN.Search($sr)
  $i = 0 ; $r.responses[0].results | foreach { 
    write-host -fore yellow "[$i] $($_.Title)"
    write-host $_.Description
    write-host -fore White $_.Url
    $i += 1

  # Process Choices till Quit is chosen

  $Continue  = $true
  while ($Continue) {
    $Choice = Prompt-Continue
    switch -regEx($choice) {
      10 {
           $S.Offset += 10
           $R = $MSN.Search($sr)
           $i = 0 ; $r.responses[0].results | foreach { 
             write-host -fore yellow "[$i] $($_.Title)"
             write-host $_.Description
             write-host -fore White $_.Url
             $i += 1
      11 {$Continue = $false;break}
      [0-9] {(new-object -com shell.application).ShellExecute($r.responses[0].results[($_)].url)}

posted by /\/\o\/\/
 0 comments links to this post

Wednesday, February 01, 2006


Search with MSNSearch Web API from MSH (Part 1)

This is the first part of a series about using MSN Search Web Service from MSH.

Before we can start to use the MSN Search Web Service API from MSH we need to do a couple of things first :

The first step is to Get an AppID (in Developer Help)

You need use this AppID later in the script, as you connect to the Web API

You need to sign in to the Passport Network, and give an Applicationname to get this ID.

For more info see MSN Search section of the MSN Developer Center

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 :

MSH>$compiler = "$env:windir/Microsoft.NET/Framework/v2.0.50727/csc"

MSH>&$compiler /target:library MSNSearchService.cs

Now we got a DLL that we can load in MSH :


GAC    Version        Location
---    -------        --------
False  v2.0.50727     g:\mowsh\MSNSearchService.dll

Now we are Ready to make use of the Web Service just like we use .NET objects.

we just declare them with New-Object and start using them.


# Declare MSH Seach Service Object

$MSN = new-object MSNSearchService

# Declare a source request

$s = new-object SourceRequest
$s.source = [sourcetype]::web
$s.ResultFields = ([ResultFieldMask]::All

# Declare a Search request (You need to Provide your AppID here !!)

$sr = new-object SearchRequest
$sr.AppID = "YOUR appID HERE !!!!!!!!"
$sr.Requests = $S
$sr.Flags = [SearchFlags]::None
$sr.CultureInfo = "en-US"

# Set the Query 

$sr.query = "win32_QuotaEvent"

# Do the Search   

$r = new-object sourceResponse
$r = $MSN.Search($sr)

# output results

$r.responses[0].results | select Title,Description,Url | fl

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.

$sr.query = "mow"
$r = $MSN.Search($sr)


I think it is very cool, it take a while to set it up, but then it's very easy and powerfull to use MSN search from MSH like this,

In the next part, more about "Paged" results and Making the Links Usefull,
and I will make it more a script.

enjoy your searches,

gr /\/\o\/\/

Tags :

posted by /\/\o\/\/
 1 comments links to this post


October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?