/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" 2006 Winter Scripting Games "," Check spelling with MSN Search from MSH (Part 3) "," Search with MSNSearch Web API from MSH (Part 2) "," Search with MSNSearch Web API from MSH (Part 1) "," about_Switch Documentation "," Switch -regEx "," Dir, Dir and more Dir in MSH "," Simple Show-Image function for Monad "," MSH out-zip Function "," get a Users LastLogontime and Domaincontroller fro... "," ")

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")
}
$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 :


Comments:
Blogger /\/\o\/\/
yes, it is I'm thinking for some time about this alias, but you need to suppy the alias in the script everytime, I already make the mistake sometimes posting to my blog using New (my alias for new-object).

but I think I will start to use % also in bigger scripts and add a standard section to set my aliases in the template
as it reads clean enough and I'm getting to lazy for foreach also ;-)

thanks for the comment,

greetings /\/\o\/\/
 
Post a Comment



<< Home

Archives

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.
Google
 
Web mow001.blogspot.com

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