/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Einstein 2 + subtopic. "," Burn MSH ?? "," Monad and Adam (and a preview of my to-be AD provi... "," Windows MineSweeper cheat "," erroraction on new-item, my Wrong use of Stringbui... "," MSH Minesweeper GUI game "," MSH get-WmiMethodHelp (GWM) Update + format tips. "," More on Cryptograpy and MSH "," Get-credential and Decrypting a SecureString in MSH "," Atari Laptop (no MSH content) "," ")

Thursday, November 24, 2005

 


Tuning MSH in your Profile



In this blogentry I show you part of my profile, (and in the process a list of the previous entry’s most usefull for tuning MSH) to give an example how to set MSH to your own needs.

But First an update to the Minesweeper sample, MSH Minesweeper GUI game , as it more or less started this subject.

You need to load the Windows forms Library for it to work :

[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

If you do not, you get a bunch of errors, I forgot to include the line in the script, this was partly a mistake, as some users can not run the script, see all the errors and will give up.
This issue was already mentioned earlier to me by martin but I have problems with updating. If you did read more of the blog before, you might know why, I still have a problems with my Pipelines if I edit the post I will lose them again. They are difficult to find, so I could mess it even more up by editing (I decided to add a comment).

But why I say partly ?

That’s because normally I would not need this in my script because it’s already loaded.
As it gets loaded in my profile, and it’s no use to load it again, so it was a mistake on the blog but not in the script (or was it ? ;-) ).

That is why I did not notice it was missing in the script when I did post it, I remember myself commenting it on another blog before so I think I’m not the only one where this is the case, there are chances that you also did not notice it. (for example if you have the MSH Object Viewer in your profile ot just did run it before in the session, as that was the case in my situation or another script that uses it.)

But anyway this made me decide to put some more info about the tuning I did in the MSH Profile.

There is an excellent blogitem about the Profiles and there locations in MSH here :

http://tfl09.blogspot.com/2005/10/customising-monad-via-profile-files.html

so I skip that part and go to the customizing I did (I only use 1 profile, the “All users” and even that contains only 1 line as you will see).

Fist watch that you have 3 options.

1) You have installed the 2015 version
2) You installed MSH for RTM
3) You Upgraded from the 2015 version

In the 1st case, you will have some set-alias lines in the “All Users” profile.msh, this are the standard aliases I recommend you keep them, in the 2nd case you will have them to after the upgrade but in this case you get a lot of errors while starting MSH this is because they are moved into the host code which gets run before the profiles do, and you can just remove them in the profile and just remove them.

I’m Monad for .NET 2.0 RTM (Upgraded, So I don’t have them, also I tried removing the standard functions and they also kept on working (so a educated guess would be the moved them to the host-code to ?) so my profile is almost empty(If you fresh installed I think it will be Empty), it only contains the following line :

. g:\MowSH\MowProfile.MSH g:\MowSH

I just call my own script from it, this makes me flexible, I want it for all users now but I could easily change this by putting the line in another profile,
The dot is for loading the script in the current scope as we want the variables to stay ;-).
I give the directory where I did put the helper scripts (as you will see later) as an argument, to Fill the $MowMSH variable, that is my "Monad Profile", but you can just do it in the profile if you want (as you see before the last upgrade was even too safe ;-) ), but I like it this way because I just put the Dir on my USB stick and I just have to copy it and add 1 line to a MSH profile of choose and I’m all tuned.
The MowSH is because it’s my Own build shell (for my own provider and CMDlets)
another way to tune MSH, but I will blog about that later :

The DirectoryStructure below the MowSH dir looks like this :

MowProfile.msh

And the following directories :

CMDLets
Functions
Lib
Providers
Tools
TypeData
Scripts
Bin

My Profile looks like this (I shortened it a bit):

$MowMsh = $args[0]

# Set Prompt

function prompt { $Dir = get-location; $host.ui.rawui.windowtitle = "/\/\o\/\/SH - $dir";Write-Host -nonewline -ForeGroundColor Red MSH;">" }

# Extra Drives

& {
get-drive | forEach {$str = "function global:$($_.name): { set-location $($_.name): } ";invoke-command $str}
Function global:var: {set-Location variable:}
Function global:fun: {set-Location function:}
}

# Load .NET Classes

[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

# Load Custom .NET Class Libraries

[void][System.Reflection.Assembly]::LoadFile("$MowMsh\Lib\MowClipBoard.dll")

# Load Custom TypeData

update-typeData "$mowmsh\TypeData\mowtypes.mshxml"

# Custom Aliases

set-alias new new-object

# ShortCut Functions (Internal)
Function cd.. {cd ..}
Function Start. {(new-object -com shell.application).Explore((pwd).tostring())}
function in-host {[system.console]::in.readtoend()}
function CopyCon{
if ($args[0] -eq $null) {[system.console]::in.readtoend() | out-file}
Else {[system.console]::in.readtoend() | out-file $args[0]}
}

# shorcut Fuctions (External)

function gwc {. $MowMsh\functions\Get-WmiClasses.msh}

# Critical Functions (External)

. $MowMsh\functions\View-Object.msh
. $MowMsh\functions\Get-WmiHelp.msh
. $MowMsh\functions\Get-WmiMethodHelp.msh
. $MowMsh\functions\More.msh

# Not Critical Functions

. $MowMsh\functions\Wipe-Screen.msh
. $MowMsh\functions\Throw-Dices.msh



I walk trough it, as most of the customizing, I did blog about before, just follow the links for more information about that item.

First the Prompt :
red MSH> prompt
Get Current dir in MSH consoleTtitle

Some Extra drives I like.
Get driveletters for All drives (Providers) in MSH
Notice the new scope here to Keep the Helpervariables out of scope,


The .Net libraries I want standard loaded
(here is the form that started this, only hidden in the OV before)

Custom DLL’s,
custom .NET libraries, this are not the CMDlets !!, as they are compiled in the custom shell (also topic for a later blog I think, the beta doc’s (see $links-section on bottom of page) also have good info on this), but this are “Normal” .NET classes I want to load, for an example see :
MSH Clipboard part 2 (of 3 ?)

Custom Typedata :
Another very strong way to tune your MSH environment !!
Update-TypeData (Democracy to the types)

Custom aliases

I don’t have much at the moment (as I would forget and post scripts with them ;-) ), but I do make a lot “on-the-fly” when working on something.

Some shortcut functions I like

CopyCon : adopted on Reskit http://www.reskit.net/monad/samplescripts.htm
The rest is self explainatory I think

Some shortcut functions to scripts I start often , as getWmiClasses.MSH.
" Wmi-Help Part 1 " Getting All the WMI Classes and Descriptions in a HashTable

But that I don’t want to load for 1 second every time I start the shell, so I don’t load the actual script Here, but I only make I shortcut GWC that call’s the script (I changed the script a bit for this, I loaded it in a new scope and made the variable global, JS advised against it, but in this case the whole point of the script is to put it Global so I did it anyway ;-) ), the script: scope is normaly better for this.

& {
$global:wmiClasses
}


Some bigger scripts I consider critical .

MSH Object Viewer : by far my most used function,
as replacement to GM,
to configure .NET objects ,
to browse WMI. (I renamed it to the view-object to be more consisted with MSH naming , but I still use it as object e.g OV(gi .) also.


" WMI help Part 2 ",Getting Help on WMI classes, ( get-WmiHelp (GWH) Function)"

WMI help Part 3 (Methods) ", Getting Help on Methods and generating Sample Scripts.
(Updated version)

To view al instances of a WMI class
WMI viewer script for MSH (GUI)

And the not critical functions I still want to keep handy,
Wipe the screen in MSH (just want to do it like this some times, mostly I need a smoke then ;-) , that’s why I can’t wait for the burn version ;-)
Thow Dices in MSH (for example to answer who gets coffee ?)

I did leave out a handful of functions I would not think you care about, also I still have a lot of usefull scripts that I just load when Needed, or still need to add as it's a bit older profile.

This blogentry got a lot bigger as I planned but I think this gave a good example if the different way’s to tune monad.

- profile
- typedata
- cmdlets
- providers

and focusing on the Profile, the different way’s to load or just alias items within a Profile.

I hope this info helps you tuning your MSH environment to your own wishes.

Gr /\/\o\/\/





Comments:
Blogger Sung Meister
Would you be able to tell me how long it takes for your MSH to start up?

I wonder if it is a good idea to put so many custom functions and calls instead of creating a new shell using "make-shell.exe"
 
Blogger /\/\o\/\/
I can not see the difference between with or without this profile.

both around a second, a bit less

but this profile is still almost "clean" ;-)
the only thing that took some time to load, the get-WMIclass I did just alias ;-)

b.t.w. it's not realy a choice between loading scripts in the profile, or extend the shell with your own CMDlet's or providers.

it's a different thing, the choice is between startup time and have a lot of functions handy,
but I'm are far from that with the profile shown . ;-)


gr /\/\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?