/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Tip from Monad "," MSH AD querying with .NET 2.0 framework "," get AD user allowed Logonhours from MSH "," MSH Show-Byte Function "," Let monad "drop" some chars "," getting an Inputbox in MOnad "," Get AD info into a nested HashTable from MSH "," Logging your MSH session "," MSH get-dateFormat function "," Working with a Path in MSH "," ")

Wednesday, December 07, 2005

 


Monad -and More bytes with -band = shorter script



For the script MSH Show-Byte Function , I found a much shorter solution yesterday :



MSH>$byte = 23
MSH>for ($i=0;$i -lt 8;$i++){if ($byte -band [math]::pow(2,$i)) {"$i Set"} else {"$i"} }
0 Set
1 Set
2 Set
3
4 Set
5
6
7
Exept from the nicer layout, does does basicly the same, gives you the bits that are set in a byte.
so now it's also easy to make this script, to only 14 lines.
get AD user allowed Logonhours from MSH
Another thing you might notice is the $bits array is gone.
that's becouse I only made this workaround, because I forgot about this :

[math]::pow(2,0)

that's another thing I like about Monad it forces me to think about things I once did know but are now hidden in libraries and Past&Copy files.

so, it's not alway's is a bad thing to re-invent the weel.(as you might find a cheaper way to make it (shorter / easier), and refresh some old Math on the way. ;-) thx Markus

also nice is I think the way I came to use the Binary AND function.

It started like this :


MSH>(gi .) | gm
MSH>(gi .) | gm

TypeName: System.IO.DirectoryInfo

Name MemberType Definition
---- ---------- ----------
....
....
Mode ScriptProperty System.Object Mode {get=$catr = "";


then I did see the Mode script property, that got me thinking as this is a bin value also, let's look how it's done :

so I did :

MSH>(gi .) | gm | fl
....
.....

TypeName : System.IO.DirectoryInfo
Name : Mode
MemberType : ScriptProperty
Definition : System.Object Mode {get=$catr = "";
if ( $this.Attributes -band 16 ) { $catr += "d" } else { $catr += "z" };
if ( $this.Attributes -band 32 ) { $catr += "a" } else { $catr += "-" } ;
if ( $this.Attributes -band 1 ) { $catr += "r" } else { $catr += "-" } ;
if ( $this.Attributes -band 2 ) { $catr += "h" } else { $catr += "-" } ;
if ( $this.Attributes -band 4 ) { $catr += "s" } else { $catr += "-" } ;
$catr;}


then this in the Monad dir :


MSH>match-string "-band" *.txt
about_Comparison_operators.help.txt:148: -band bitwise and 10 -band 3 2
about_Comparison_operators.help.txt:151: When the -band is used to compare values, the compared bits must
about_where.help.txt:30: -band Bitwise and
about_where.help.txt:61: -band bitwise AND


and that got me to this remake of the scripts.

I think a nice example how Monad teaches you about itself.

to bad the drive-example, is gone to the host also, as it was also a nice example of this (see Tuning MSH in your Profile )


gr /\/\o\/\/


Comments: Post a Comment

Links to this post:

Create a Link



<< 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?