This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
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")
}
$sb.ToString()
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.
enjoy,
gr /\/\o\/\/
Tags : Monad msh