An Other issue that did cost me a lot of time was that if you trap an Error,and there is an Error in the TRAP MSH will point you at the wrong place(at the foreach, that had the trap in it.)

See example below.

as my function was a bit bigger,and I did not have the helper Writes ($_.name and "Trap") that I put in the Example to point me the way. ( WMI viewer script for MSH (GUI) ), It took me some time to find this out.

So don't make errors in your TRAP's !!!

gr /\/\o\/\/

PS I know that it is a bit ugly this way, but still the error is confusing.(in productioncode I would check first and not Trap the Error)

Get-Member will not show me DataTables or collections.how do I look at there methods and properties?as you can see in the example below that MSH will not even give me A get Member on a DataTable (say's I have no Object, but as you see I can work with it only I can't see wat I'm doing ;-()

That is Till I add a Datarows to itthen it will not give me the dataRowCollection but a dataRow,that's 3 levels deeper than tat I asked for !

in Monad" Shell Beta 2 (for .NET Framework 2.0 RC/RTM),the default execution policy is set to a mode called "Restricted."The first time you run a script in the new shell, you’ll see the following error message:

The file C:\my_script.msh cannot be loaded. The execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

Sunday, October 30, 2005

I Like sometimes a quick overview of I WMI class,the MSH script below adds the Function :

get-WMIDatagrid (GWD)

to MSH, with this function you can look at the Instances of a WMI Object in a Datagrid.I will first grab all Instances of the Class and add all the properties to a DataTable.then it will launce a form with a Datagrid linked to the Generated DataTable.this gives you a quick overview of the Class and the instances.

for example :

MSH> GWD win32_share

gr /\/\o\/\/

PS as I get All the Data you can get problems with a few classes (for example the Eventlog) that have very much data in them.(but there are only a few of them)

while working in AD with MSH, I noticed the new (.NET 2.0) namesspace :

System.DirectoryServices.ActiveDirectory

there are some very Handy classes there, that make working with AD,(especialy the infrastructure part) a lot easier.Some Examples below (but do a get-member on the Object, there are a lot more handy properties and methods here !!)

Sunday, October 23, 2005

after my POC, it was a bit more work as I did expect at first.because I needed threads,Hence I needed events to put the data back.also I needed a ParameterizedThreadStart, to get input to the thread.

basicly I made 2 classes, one I call from MSH (ClipBoard), and 1 class STA that gets called by the Clipboard class on a STA thread.

if it has to return something, it will Raise a Ready Event that ClipBoard will Handle.

the function in the Clipboard-class will loop until the STA tread is ready, and then returns the result to MSH.

As for every function in the original Class, I had to make 2 functions in my wrapper, and I needed some EventHandlers there is a lot of boilerCode.so I did not (yet ?) do All Methods of te original object.but the rest is more of the same (.. and boring)I did all the Contains except data, and the get / set as Text.

gr /\/\o\/\/

you can find the wrapper (MowClipboard.dll) hereAfter you load it you can do things like this :

> I believe you need to set the principle policy to WindowsPrinciple first,> otherwise you get a GenericPrinciple by default:> > AppDomain myDomain = Thread.GetDomain();> myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);> WindowsPrincipal myPrincipal = >(WindowsPrincipal)Thread.CurrentPrincipal;>

while playing with the MY object in a former post,I noticed that the MSH will exit if called from MSH.

I posted this on the newsgroup, and got the following aswer :

Sorry - this is a known problem. Execution threads in the monad engine arecreated MTA and you can't create an object that requires STA from an MTAthread. We have workaround code in the new-object cmdlet that let's youcreate an STA COM object when you create the object explicitly. Unfortunatelythis doesn't work for objects that are created implicitly by a .NET object.We instantiate the .NET object and some time later it instantiates the COMobject. We can't use the same workaround because we don't get the exceptionuntil the first time the object is used instead of when it's created. Anyway- we're still working on this and will hopefully have a solution soon.-bruce--Bruce PayetteMonad DevelopmentMicrosoft CorporationThis posting is provided "AS IS" with no warranties, and confers no rights.I have found the following workaround for it :

gr /\/\o\/\/

PS, it's more a POC (proof-of-Concept), it will only write the line "Hello Clip" (hard-coded),You need to make it a function that takes arguments, or better yet a CMDlet. to make it realy usefull ;-)

PS 2 returning the ActiveDS.IADsGroup,TLB loaded also in MSH). gives this fine red error, and the shell will exit ( but the message is fair enough (only why quit the shell)

MSH G:\> $r gm An error has occurred that was not properly handled. Additional information is shown below. The command shell will exit. Unhandled Exception: System.Runtime.InteropServices.InvalidComObjectException: C OM object that has been separated from its underlying RCW cannot be used. .............. .............

so we need a way to bind the RCW in MSH,anyone some Idees ?

anyway you still can do alot of things from the current workaraund :start stop services, get local SID's etc. on the Winnt: provider.

only if you get an IADs object back it will not work.

for the rest I like the Way I can put the "VB.NET code online, ofcourse if you implemt this i na function you can better complile the DLL but this is nice for testing.

they are reachable from the fileSystemObject, but a bit hidden and you need a .NET (2.0) class [System.Security.Principal.ntaccount]to get to them. (took me to the winFX SDK to find it, its new in .NET 2.0.

* tip as usual in MSH you get an Object back so try a get-member on the returned SID !

the Set_owner : will take a security principal and set the owner with it(I will look where you can get them later, for now I just coppied the owner from 1 file to Another.

the last one Gets the WMI_info from the file. (this I got from a newsgroup post from Jeffrey Snover )this gives you alot more info then the FileSystemInfo class alone.

Friday, October 21, 2005

there are some troubles with using the Filewatcher class for monitoring file changes.in MSH.

Main problem is that the filewatcher is on another Thread, hence you can't (yet) use a delegate .

"Jeff Jones [MSFT]" wrote:This is a known issue where if theScriptBlock gets called on a different thread then it cannot be invoked.It looks like the plan for V1 is to improve the error message and then possiblytake a fix in V2.

I did this online with CodeHTMLer, verry Cool !!, also because the MSH text is difficult to past in the Blogger web-interface.(linebreaks are gone, and screenlines get broken )I think It's alot more readable this way

I found the link to this this here,

http://www.proudlyserving.com/archives/2005/10/prettifying_mon.html

and a link to a blog with also MSH info :(a.o. nice script to convert doskey macros to Monad functions)

PS If you got any nice One-liners plz post them as a comment.(bit like the good old Atari - one-liner compititions ;-)easy to play "False" in Monad by using ; LOL,did someOne reached the limit (is it 256 ?) yet ?

I needed to Change Default view in explorer,for Ca 1500 XP clients and reset the views.(changing this when Grouppolicy is applied a.o. "Classic Shell" (that messed up the settings in the first place - reason for the request) etc. is another topic - and not funny ! - if you need too.. good luck ... search the unattended newsgroups for the registry-settings.. and check the GPO settings - the code below works at my home box but still not on my client in the customers domain - so we stopped by removing the "Classic shell"-GP setting, but ok, other story)

and I could not use MSH for this anyway (Yet),but as I'm already getting used to prototyping in MSH. (I think the Guys who already played a bit with it know why ;-)),hence I started there :

but the proto-typing in MSH (changing the reg was a nice adventure)

First getting there :

Change to the CurrentUser key :

MSH C:\> cd HKCU:

nice and easy ;-) so now to the softwarekey

cd so[tab]

MSH HKCU:\> cd Software

cd mi/[tab]\wi[tab]\cu[tab]\ex[tab]\Str[tab][tab]

MSH HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams>

Tab completion in the Regprovider so it realy browses like a dir (I realy like this)

GP = get-Property, we are getting the properties of the current Key.looks a bit strange maybe, because we are (still) thinking filesystem when in the reg-provider when navigating but if you come to the place you want to be and going to the actions it comes clear then the fun starts :

, but since I copy the line to a script that I want to be able to run form anywhere I do it this way (and I can do "cd C:" to get a short prompt - you can change the prompt but thats also dangerous IMHO because you will not see wat you do)

you see that the last part is a bit more complex since you have to deal with the wrapper, and easy to do wrong (use the 2 step variable declaration to avoid confusion). this can also happen with "simpler" keys like 123.

I hope this post will help you exploring the Reg with MSH

enjoy ..

gr /\/\o\/\/

PS. thx to Jeff Jones [MSFT] for helping me with this in mp.w.s.scripting

#Objectviewer.msh# will show an Object in a PropertyGrid (propertywindow in Visual Studio)# this is an easy way to look at MSH objects.# you can read / write the object properties.# and it has some nice editors for some properties# eg. ov (gi test.txt)will let you change the date by a calendarview# /\/\o\/\/ 2005

The documents included are:The "Getting Started" guide, an 80-page introduction to using the shell and the MSH language supported by the Windows "Monad" Shell (GettingStarted.doc).A single-page summary of the MSH language, formatted as a tri-fold (LanguageQuickReferenceTriFold.doc).A quick-start guide to tracing in the Windows "Monad" Shell (TracingQuickStart.doc).The three Hands-On Labs from the 2005 Professional Developers Conference: "Monad Scripting" (MonadScripting-HandsOnLab.doc), "Building Monad Cmdlets" (BuildingMonadCmdlets-HandsOnLab.doc) and "Creating Monad Providers" (CreatingMonadProviders-HandsOnLab.doc).

recently did a channel9 interview. I wanted to discuss the recent wave of innovation around Whidbey but ended up discussing lots of stuff including an update on Monad, the democratization of type systems, epistemology, Exchange, economics, SMASH, the needs of admins, the last mile, and much more. As such, it isn't a very structured, planned, or linear conversation. You might find that an good thing or a bad thing. Anyway - you are forewarned and if you are interested you can see it at:http://channel9.msdn.com/Showpost.aspx?postid=127819--