<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-18213836</id><updated>2011-07-28T07:46:37.997-04:00</updated><title type='text'>::::::::: PowerShell :::::::::</title><subtitle type='html'>Let's get lazy with PowerShell!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>44</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-18213836.post-7003071502563546812</id><published>2006-11-30T20:17:00.000-05:00</published><updated>2006-11-30T21:05:04.594-05:00</updated><title type='text'>Installing PowerShell with Unattended Windows CD</title><content type='html'>Here are some steps to include Windows PowerShell(for English Version of Windows XP w/ SP2) in an unattended Windows CD.&lt;br /&gt;&lt;br /&gt;First,&lt;br /&gt;I have copied Windows CD content to "C:\xpcd"&lt;br /&gt;Windows PowerShell installation file, &lt;span style="font-style: italic;"&gt;WindowsXP-KB926139-x86-ENU.exe&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;,&lt;/span&gt;&lt;span&gt; has been copied over to &lt;span style="font-style: italic;"&gt;C:\xpcd\$OEM$\$1\install\applications\&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create a batch file, &lt;span style="font-style: italic;"&gt;install_applications.cmd&lt;/span&gt; (just name it to anything with &lt;span style="font-style: italic;"&gt;.bat&lt;/span&gt; or &lt;span style="font-style: italic;"&gt;.cmd &lt;/span&gt;extension) at &lt;span style="font-style: italic;"&gt;C:\xpcd\$OEM$\$1\install&lt;/span&gt;&lt;/li&gt;&lt;li&gt;Open up &lt;span style="font-style: italic;"&gt;Winnt.sif&lt;/span&gt; and create a &lt;span style="font-style: italic;"&gt;[GuiRunOnce]&lt;/span&gt; section and call the batch file created in the previous step.&lt;/li&gt;&lt;li&gt;Simply call PowerShell installation file with silent setup switches in the batch file&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;Winnt.Sif&lt;/span&gt;:&lt;br /&gt;[GuiRunOnce]&lt;br /&gt;%systemdrive%\install\install_applications.cmd&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;install_applications.cmd:&lt;/span&gt;&lt;br /&gt;... other application installation statements...&lt;br /&gt;...&lt;br /&gt;ECHO.&lt;br /&gt;ECHO Installing PowerShell&lt;br /&gt;ECHO Please wait...&lt;br /&gt;start /wait %systemdrive%\install\applications\WindowsXP-KB926139-x86-ENU.exe /quiet /passive /norestart&lt;br /&gt;exit&lt;/blockquote&gt;&lt;br /&gt;Yes... Now I have a Windows XP CD with Windows PowerShell.&lt;br /&gt;I have installed Windows XP and saw other applications (WinZip, IrfanView, etc...) being installed.&lt;br /&gt;Since PowerShell was to be installed in a silent mode, I didn't expect to see anything happening.&lt;br /&gt;But 10 minutes later, PowerShell wasn't still installed.&lt;br /&gt;&lt;br /&gt;Oh yes.  I have forgotten to include .NET Framework 2.0 onto the CD...&lt;br /&gt;Well, download .NET 2.0 redistributable(i have placed the installation file under  &lt;span style="font-style: italic;"&gt;C:\xpcd\$OEM$\$1\install\applications\DotNet\2\dotnetfx.exe&lt;/span&gt;).&lt;br /&gt;And you must include the following script &lt;span style="font-weight: bold; font-style: italic;"&gt;BEFORE&lt;/span&gt; installing PowerShell so that the result is &lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;install_applications.cmd:&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;ECHO.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;ECHO Installing .NET Framework 2.0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;ECHO Please wait...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;start /wait %systemdrive%\install\applications\DotNet\2\dotnetfx.exe /q:a /c:"install.exe /qb"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;ECHO.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;ECHO Installing PowerShell&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;ECHO Please wait...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;start /wait %systemdrive%\install\applications\WindowsXP-KB926139-x86-ENU.exe /quiet /passive /norestart&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;/span&gt;&lt;span&gt;Now PowerShell should install without a problem...&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;References:&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://unattended.msfn.org/"&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Unattended Installation How-To&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://groups.google.com/group/microsoft.public.windows.powershell/browse_frm/thread/13fee707478ecc95"&gt;PowerShell installation file switches (NewsGroup question...) &lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5&amp;displaylang=en"&gt;.Net 2.0 Redistributable Download Link(for x86)&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=6CCB7E0D-8F1D-4B97-A397-47BCC8BA3806&amp;amp;displaylang=en"&gt;Windows PowerShell 1.0 English-Language Installation Package for Windows XP (KB926139)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/MSH" rel="tag"&gt;MSH&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-7003071502563546812?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/7003071502563546812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=7003071502563546812' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/7003071502563546812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/7003071502563546812'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/11/installing-powershell-with-unattended.html' title='Installing PowerShell with Unattended Windows CD'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-116085704964687793</id><published>2006-10-14T16:08:00.000-04:00</published><updated>2006-10-14T16:24:17.726-04:00</updated><title type='text'>While Creating a Simple EventLog PsProvider -Part 2</title><content type='html'>I was finally able to add &lt;span style="font-style:italic;"&gt;EntryType&lt;/span&gt; dynamic parameter to &lt;span style="font-style:italic;"&gt;Get-ChildItem&lt;/span&gt;&lt;br /&gt;Been slacking off lately and finally made some time to extend &lt;span style="font-style:italic;"&gt;Get-ChildItem&lt;/span&gt; cmdlet in &lt;span style="font-style:italic;"&gt;EventLog&lt;/span&gt; provider.&lt;br /&gt;&lt;br /&gt;Now, in the following screenshot, I am in the &lt;span style="font-style:italic;"&gt;sys:&lt;/span&gt; drive of type EventLog for &lt;span style="font-style:italic;"&gt;System&lt;/span&gt; EventLog.&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Get-ChildItem&lt;/span&gt; returns list of all EventLogEntry objects for System EventLog.&lt;br /&gt;Now, I can just filter the output to display according to the EventLogEntryType of each EventLogEntry.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://img.photobucket.com/albums/v138/dance2die/powershell/Blogger/DynamicParameter-EntryType.gif"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px;" src="http://img.photobucket.com/albums/v138/dance2die/powershell/Blogger/DynamicParameter-EntryType.gif" border="0" alt="" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And what's cool is that(well about PowerShell that is, not my provider), if I pass an  invalid Enumeration value for EntryType parameter, it displays error message with valid enumeration values &lt;span style="font-weight:bold;"&gt;Error, Warning, Information, SuccessAudit, FailureAudit&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It's PowerShell in the works... not my code that displays valid enum values.&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/MSH" rel="tag"&gt;MSH&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-116085704964687793?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/116085704964687793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=116085704964687793' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/116085704964687793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/116085704964687793'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/10/while-creating-simple-eventlog_14.html' title='While Creating a Simple EventLog PsProvider -Part 2'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-116036662989254998</id><published>2006-10-09T00:03:00.000-04:00</published><updated>2006-10-09T00:07:10.786-04:00</updated><title type='text'>While Creating a Simple EventLog PsProvider (in C#)</title><content type='html'>&lt;p&gt;&amp;nbsp;When PowerShell was still called Monad, there was a PDC05 Hands-On Lab document available with Monad distribution.&amp;nbsp; The document was about "Creating Monad Providers" for Access database.&lt;/p&gt; &lt;p&gt;I have started to go over the old PDC 05 document since I could not find enough documentation to get started.&amp;nbsp; The document was a bit out-dated but it was not hard to figure out what's been changed since Monad beta 2.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Patterns and utility methods are about the same as what's used for creating AccessDb provider in the lab.&amp;nbsp; But the problem was that, I wanted to be able to create a provider-specific parameter for my PsProvider. (Let me get back to this a bit later on)&lt;/p&gt; &lt;p&gt;For e.g.).&amp;nbsp; Under Certificate provider, &lt;em&gt;Get-ChildItem&lt;/em&gt; has a Certificate-Provider specific parameter &lt;em&gt;-CodeSigningCert&lt;/em&gt; for &lt;em&gt;Get-ChildItem. &lt;/em&gt;&lt;/p&gt; &lt;p&gt;Now let's see how one can create a "sys" drive for System EventLog&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/powershell/Blogger/10082006-PsProvider/New-PsDrive2.gif"&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;You can retrieve System event log entries using &lt;em&gt;Get-ChildItem&lt;/em&gt;&amp;nbsp;cmdlet(or ls, or dir whichever alias you prefer):&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;strong&gt;ls sys:&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Above is&amp;nbsp;equivalent to:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;strong&gt;Get-EventLog -logName System&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Both &lt;em&gt;ls sys:&lt;/em&gt; and &lt;em&gt;Get-EventLog System&lt;/em&gt; returns all event log entries in System EventLog(well as you might or might not have guessed ;)) and not only they display the same content, but the output should look exactly the same.&amp;nbsp; &lt;/p&gt; &lt;p&gt;The reason that output look exactly the same is because&amp;nbsp;there is a pre-defined display format for the type &lt;em&gt;System.Diagnostics.EventLogEntry&lt;/em&gt; in &lt;em&gt;$PsHome/dotnettypes.format.ps1xml.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now, back to the provider-specific&amp;nbsp;parameter for &lt;em&gt;Get-ChildItem&lt;/em&gt;, my implementation takes in &lt;em&gt;Index&lt;/em&gt; of event log entry.&amp;nbsp; But I would also like to supply additional parameters so that &lt;em&gt;Get-Item&lt;/em&gt; can retrieve event log entry based on either &lt;em&gt;EventID&lt;/em&gt; or &lt;em&gt;InstanceID&lt;/em&gt; like the following&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;strong&gt;Get-Item -EventID 18&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Get-Item -InstanceID 198397&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Anyways, here is the current implementation of &lt;em&gt;Get-Item&lt;/em&gt; in action&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/powershell/Blogger/10082006-PsProvider/Get-Item.gif"&gt; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;(201..205) is an array holding indexes from 201 through 205 so EventLogEntry objects with Indexes between 201 and 205 are displayed.&amp;nbsp; How neat. I prefer that over&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;strong&gt;get-eventlog system | ? { ($_.Index -ge 201) -and ($_.Index -le 205) }&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;since there is no need to specify which log to list event log entries from nor use clunky syntaxes for Index ranges.&amp;nbsp; Well, one can live with above syntax but when it comes to scattered index ranges you want to select, the latter approach gets a bit too uhm, unpractically complicated.&amp;nbsp;&amp;nbsp; Try&amp;nbsp;accomplish &lt;em&gt;ls (1..5+10..15)&lt;/em&gt; using &lt;em&gt;Get-EventLog, &lt;/em&gt;it doesn't look pretty...&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Lastly, &lt;em&gt;Xaegr&lt;/em&gt; on IRC has suggested that it wouldn't hurt to add a support to get remote machine's EventLog entries.&amp;nbsp; Xaegr has suggested a UNC path like syntax&amp;nbsp;&lt;em&gt;"\\MachineName\LogName"&lt;/em&gt; for the Root string, but I just went with &lt;em&gt;MachineName:LogName&lt;/em&gt; for a quick and dirty testing...&amp;nbsp; Now, this functionality is quite buggy... so when I tried to use IP instead of hostname, I get errors like Get-Item cannot find network path, blah...&amp;nbsp;&amp;nbsp; Moreover, you should have already impersonated or authenticated to the remote machine before creating new EventLog PsDrive for the remote machine and must have appropriate privileges to read EventLog.&amp;nbsp; Since I am not systems administrator, this is a bit tough to understand...&lt;/p&gt; &lt;p&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/powershell/Blogger/10082006-PsProvider/New-PsDrive_Remote.gif"&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Well, I would appreciate it if someone could answer my question on &lt;a href="http://groups.google.com/group/microsoft.public.windows.powershell/browse_frm/thread/222cf05e36773b3e/#"&gt;NG(PowerShell News Group)&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;W00t, My first post using &lt;a href="http://windowslivewriter.spaces.live.com/"&gt;Windows Live Writer&lt;/a&gt;... Took me really long to get used to this a bit.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/MSH" rel="tag"&gt;MSH&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-116036662989254998?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/116036662989254998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=116036662989254998' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/116036662989254998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/116036662989254998'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/10/while-creating-simple-eventlog.html' title='While Creating a Simple EventLog PsProvider (in C#)'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-115548646315825443</id><published>2006-08-13T12:14:00.000-04:00</published><updated>2006-08-13T12:35:54.106-04:00</updated><title type='text'>Add-Member: Extended Example</title><content type='html'>Add-Member cmdlet provides a way to "Add(s) a user-defined custom member to an object"&lt;br /&gt;&lt;br /&gt;There are 3 examples on &lt;span style="font-weight:bold;"&gt;get-help add-member&lt;/span&gt; help file but they do not seem to quite reflect the real power of this cmdlet.&lt;br /&gt;&lt;br /&gt;Examples in the offical help document, examples deals with following cases&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Adding a &lt;span style="font-style:italic;"&gt;NoteProperty&lt;/span&gt; to an object&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Adding an &lt;span style="font-style:italic;"&gt;AliasProperty&lt;/span&gt; to an object&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Adding a &lt;span style="font-style:italic;"&gt;NoteProperty&lt;/span&gt; to an object, pass thru the result to a variable&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Extended Example&lt;br /&gt;Description&lt;/span&gt;: Add a ScriptProperty for converting From/To a Base64 string of a string&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Add "ToBase64String"&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;[^_^]PS[217]&gt;$str = "abc" -as [psobject]&lt;br /&gt;[^_^]PS[218]&gt;$str | Add-Member -MemberType ScriptProperty -Name ToBase64String `&lt;br /&gt;&gt;&gt; -Value {[System.Convert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes($this))}&lt;br /&gt;&gt;&gt;&lt;br /&gt;[^_^]PS[219]&gt;$str.ToBase64String&lt;br /&gt;YQBiAGMA&lt;/blockquote&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Add "FromBase64String"&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;[^_^]PS[220]&gt;$base64 = $str.ToBase64String&lt;br /&gt;[^_^]PS[221]&gt;$base64&lt;br /&gt;YQBiAGMA&lt;br /&gt;[^_^]PS[222]&gt;$base64 | Add-Member -MemberType ScriptProperty -Name FromBase64String `&lt;br /&gt;&gt;&gt; -Value {[System.Text.Encoding]::UNICODE.GetString([System.Convert]::FromBase64String($this))}&lt;br /&gt;&gt;&gt;&lt;br /&gt;[^_^]PS[223]&gt;$base64.FromBase64String&lt;br /&gt;abc&lt;/blockquote&gt;&lt;/li&gt;&lt;/ol&gt;Above example shows how to add a new member(ScriptProperty) to easily access a converted Base64 string from string variables&lt;br /&gt;NOTE:&lt;span style="font-style:italic;"&gt;-as [psobject]&lt;/span&gt; in the first line is necessary since &lt;span style="font-weight:bold;"&gt;Add-Member&lt;/span&gt; works only on the object of type PsObject, so &lt;span style="font-style:italic;"&gt;-as [psobject]&lt;/span&gt; is added to explicitly convert a string variable to of type PsObject&lt;br /&gt;&lt;br /&gt;On 218th statement, We add a script block(We are adding a ScriptProperty, aren't we?) to convert the current string(specified as &lt;span style="font-style:italic;"&gt;$this&lt;/span&gt;, the current object we are working on) into a Base64 representation&lt;br /&gt;Now retrieving a Base64 bytes of the string is as easy as accesing newly aded Script Property;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;$str.ToBase64String&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;On 219~222 statements, we assign the Base64 string to a new variable, &lt;span style="font-style:italic;"&gt;$base64&lt;/span&gt; and then add a new ScriptProperty member(&lt;span style="font-style:italic;"&gt;FromBase64String&lt;/span&gt;) to reverse the process(Converting Base64 string back to orignal string)&lt;br /&gt;We have added the script property the same way as we did for &lt;span style="font-style:italic;"&gt;ToBase64String&lt;/span&gt; but with different function in the script block.&lt;br /&gt;Now again, you can retrieve the orignal string through &lt;span style="font-style:italic;"&gt;From64String&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;$str.FromBase64String&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The example is a modified version of &lt;a href="http://blogs.msdn.com/powershell"&gt;PowerShell Team blog&lt;/a&gt; entry on &lt;a href="http://blogs.msdn.com/powershell/archive/2006/04/25/583265.aspx"&gt;http://blogs.msdn.com/powershell/archive/2006/04/25/583265.aspx&lt;/a&gt;.&lt;br /&gt;One might think about adding both &lt;span style="font-style:italic;"&gt;ToBase64String&lt;/span&gt; and &lt;span style="font-style:italic;"&gt;FromBase64String&lt;/span&gt; on the same variable like the following(yes, i have tried it like hmm not sure how many times...)&lt;br /&gt;&lt;blockquote&gt;[^_^]PS[258]&gt;$str = "abc" -as [PsObject]&lt;br /&gt;[^_^]PS[259]&gt;$str | Add-Member ScriptProperty ToBase64String `&lt;br /&gt;&gt;&gt; {[System.Convert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes($this))}&lt;br /&gt;&gt;&gt;&lt;br /&gt;[^_^]PS[260]&gt;$str | Add-Member ScriptProperty FromBase64String `&lt;br /&gt;&gt;&gt; {[System.Text.Encoding]::UNICODE.GetString([System.Convert]::FromBase64String($this))}&lt;br /&gt;&gt;&gt;&lt;br /&gt;[^_^]PS[261]&gt;$str.ToBase64String&lt;br /&gt;YQBiAGMA&lt;br /&gt;[^_^]PS[262]&gt;$str.ToBase64String.FromBase64String&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;But &lt;span style="font-style:italic;"&gt;$str.ToBase64String.FromBase64String&lt;/span&gt; does not produce any result because &lt;span style="font-style:italic;"&gt;$str.ToBase64String&lt;/span&gt; is not &lt;span style="font-style:italic;"&gt;$str&lt;/span&gt; but a string returned as a result of Script Property method.(Would anyone correct me if I got it wrong?)&lt;br /&gt;&lt;br /&gt;In the Team Blog Entry, in which talks about extending Type definition to add above script properties, above scenario works since type definition extends &lt;span style="font-style:italic;"&gt;System.String&lt;/span&gt; type itself&lt;br /&gt;&lt;br /&gt;so even &lt;span style="font-style:italic;"&gt;$str.ToBase64String.FromBase64String&lt;/span&gt; as well as ScriptProperty being permanent(not just available through the current session but "across" sessions)&lt;br /&gt;&lt;br /&gt;You can find more examples and ideas to extend on Mow's blog entry, &lt;a href="http://mow001.blogspot.com/2006/01/some-fun-with-monads-add-member-mp3.html"&gt;Some fun With Monads Add-Member, MP3 files and COM&lt;/a&gt; and &lt;a href="http://del.icio.us/powershell/ExtendedTypeSystem"&gt;http://del.icio.us/powershell/ExtendedTypeSystem&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/MSH" rel="tag"&gt;MSH&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt; &lt;a href="http://technorati.com/tag/cmdlet%3AAdd-Member" rel="tag"&gt;cmdlet:Add-Member&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-115548646315825443?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/115548646315825443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=115548646315825443' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115548646315825443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115548646315825443'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/08/add-member-extended-example.html' title='Add-Member: Extended Example'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-115418965866296992</id><published>2006-07-29T11:29:00.000-04:00</published><updated>2006-07-29T12:14:50.643-04:00</updated><title type='text'>Back up SQL Server database with SQL Server Objects(SMO) using PowerShell</title><content type='html'>It is easy to set up SQL Server Agent jobs to backup database in timely fashion.&lt;br /&gt;But why not in PowerShell while SMO is exposed in .NET assembly?&lt;br /&gt;&lt;br /&gt;Usage:&lt;br /&gt;Backup-Database -dbName [string] -deviceNames [string[]] [-deviceType [Microsoft.SqlServer.Management.Smo.DeviceType]] [-Overwrite [Switch]] [[-Differential] [Switch]]&lt;br /&gt;&lt;br /&gt;Parameters:&lt;ul&gt;&lt;li&gt;-dbName: Database name to back up e.g.) pubs, AdventureWorks, NorthWind&lt;/li&gt;&lt;li&gt;-deviceNames: tape back up device name or File system name e.g.) c:/bak/pubs.bak, c:/bak/pubs_diff.bak&lt;/li&gt;&lt;li&gt;-deviceType: One of "LogicalDevice, Tape, File, Pipe, VirtualDevice"&lt;/li&gt;&lt;li&gt;-Overwrite: overwite existing backup set&lt;/li&gt;&lt;li&gt;-Differential: create a differential backup&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Examples:&lt;br /&gt;&lt;a href="http://photobucket.com" target="_blank"&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/powershell/Backup-Database.gif" alt="Photobucket - Video and Image Hosting" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;There are times that you do not know all the device types available,&lt;br /&gt;then simply enter invalid device type&lt;br /&gt;A great feature of PowerShell is that PowerShell will enumerate DeviceType&lt;br /&gt;and kindly give you list of valid device type names when invalid type is entered&lt;br /&gt;&lt;blockquote&gt;[^_^]PS[597]&gt;Backup-Database -dbName:pubs -deviceNames:'d:\bak\pubs.bak' -deviceType:DontKnow&lt;br /&gt;Backup-Database : Cannot convert value "DontKnow" to type "Microsoft.SqlServer.Management.Smo.DeviceType" due to invali&lt;br /&gt;d enumeration values. The possible enumeration values are &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;"LogicalDevice, Tape, File, Pipe, VirtualDevice"&lt;/span&gt;.&lt;br /&gt;At line:1 char:73&lt;br /&gt;+ Backup-Database -dbName:pubs -deviceNames:'d:\bak\pubs.bak' -deviceType:D &lt;&lt;&lt;&lt;&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Prerequisites:&lt;ol&gt;&lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=D09C1D60-A13C-4479-9B91-9E8B9D835CDC&amp;amp;displaylang=en"&gt;&lt;br /&gt;Microsoft SQL Server 2005 Management Objects Collection&lt;/a&gt;: You need to download and install one of &lt;i&gt;SQLServer2005_XMO_&lt;arch&gt;.msi&lt;/arch&gt;&lt;/i&gt; versions&lt;/li&gt;&lt;li&gt;How to create $server variable: Refer to &lt;a href="http://www.sqlteam.com/item.asp?ItemID=23185"&gt;Scripting Database Objects using SMO (Updated)&lt;/a&gt; on SqlTeam.com&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Source:&lt;br /&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: green"&gt;# author: Sung Kim&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;# Description: Create Full or Differential backups for &lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;#   SQL Server database with SQL Server Objects(SMO) using PowerShell&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; Backup-Database {&lt;br /&gt;  param([&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;]$dbName = $(throw &lt;SPAN style="COLOR: maroon"&gt;'Enter Database name to backup'&lt;/SPAN&gt;), &lt;br /&gt;       [&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;[]]$deviceNames = $(throw &lt;SPAN style="COLOR: maroon"&gt;'Enter device name(s)'&lt;/SPAN&gt;),&lt;br /&gt;       [Microsoft.SqlServer.Management.Smo.DeviceType]$deviceType = &lt;br /&gt;         [Microsoft.SqlServer.Management.Smo.DeviceType]File,&lt;br /&gt;       [Microsoft.SqlServer.Management.Smo.Server]$server,&lt;br /&gt;       [&lt;SPAN style="COLOR: blue"&gt;switch&lt;/SPAN&gt;]$Overwrite = $&lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;,&lt;br /&gt;       [&lt;SPAN style="COLOR: blue"&gt;switch&lt;/SPAN&gt;]$Differential = $&lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;)&lt;br /&gt;  &lt;br /&gt;  trap { &lt;SPAN style="COLOR: blue"&gt;break&lt;/SPAN&gt;; }&lt;br /&gt;  &lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# Load SMO assembly&lt;/SPAN&gt;&lt;br /&gt;  $PRIVATE:SmoDir = &lt;br /&gt;    &lt;SPAN style="COLOR: maroon"&gt;'C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies'&lt;/SPAN&gt;&lt;br /&gt;  [System.Reflection.Assembly]::LoadFile(&lt;br /&gt;    &lt;SPAN style="COLOR: maroon"&gt;"$PRIVATE:SmoDir\Microsoft.SqlServer.Smo.dll"&lt;/SPAN&gt;) | out-&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# Initialize backup object&lt;/SPAN&gt;&lt;br /&gt;  $PRIVATE:bkp = New-&lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt; Microsoft.SqlServer.Management.Smo.Backup&lt;br /&gt;  $PRIVATE:bkp.Database = $dbName&lt;br /&gt;  $PRIVATE:bkp.Initialize = $Overwrite&lt;br /&gt;  $PRIVATE:bkp.Incremental = $Differential&lt;br /&gt;  &lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# Add backup devices to backup database to&lt;/SPAN&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; ($PRIVATE:deviceName &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; $deviceNames) {&lt;br /&gt;    $PRIVATE:bkpItem = &lt;br /&gt;      new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; Microsoft.SqlServer.Management.Smo.BackupDeviceItem(&lt;br /&gt;        $PRIVATE:deviceName, &lt;br /&gt;        [Microsoft.SqlServer.Management.Smo.DeviceType]$deviceType)&lt;br /&gt;    $PRIVATE:bkp.Devices.Add($PRIVATE:bkpItem)&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($Overwrite) {&lt;br /&gt;    Write-Warning &lt;SPAN style="COLOR: maroon"&gt;"Overwriting existing backup set"&lt;/SPAN&gt;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  $PRIVATE:bkp.SqlBackup($server)&lt;br /&gt;  &lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($Differential) {&lt;br /&gt;    Write-Host -NoNewLine -F Blue &lt;SPAN style="COLOR: maroon"&gt;"Differential Backup: "&lt;/SPAN&gt;&lt;br /&gt;  }&lt;br /&gt;  Write-Host -NoNewLine &lt;SPAN style="COLOR: maroon"&gt;"$($dbName) has been backed up to "&lt;/SPAN&gt;&lt;br /&gt;  Write-Host -ForegroundColor Cyan -NoNewLine &lt;SPAN style="COLOR: maroon"&gt;"$($deviceNames)"&lt;/SPAN&gt; &lt;br /&gt;  Write-Host &lt;SPAN style="COLOR: maroon"&gt;" successfully"&lt;/SPAN&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt; &lt;a href="http://technorati.com/tag/SMO" rel="tag"&gt;SMO&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-115418965866296992?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/115418965866296992/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=115418965866296992' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115418965866296992'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115418965866296992'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/07/back-up-sql-server-database-with-sql.html' title='Back up SQL Server database with SQL Server Objects(SMO) using PowerShell'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-115293328677766190</id><published>2006-07-14T22:57:00.000-04:00</published><updated>2006-07-14T23:19:31.083-04:00</updated><title type='text'>Re-inventing the wheel for fun.</title><content type='html'>I was going through &lt;a href="http://www.microsoft.com/technet/scriptcenter/csc/default.mspx"&gt;Community-Submitted Scripts Center on Microsoft TechNet&lt;/a&gt; and came across a script named, &lt;a href="http://www.microsoft.com/technet/scriptcenter/csc/scripts/backup/backup/cscbk013.mspx"&gt;"BackupFiles.ps1"&lt;/a&gt; by Greg Lyon.&lt;br /&gt;&lt;br /&gt;The script is functional and works.&lt;br /&gt;But I didn't like the fact that it looked more like a VBScript script than a PowerShell script.&lt;br /&gt;Moreover, the script was heavily utilizing a COM object instance of type "Scripting.FileSystemObject".&lt;br /&gt;&lt;br /&gt;My goal was simply to change the code to make it look more PowerShell-like(uhm, this should mean different for different people, but in my case, i tend to use "PowerShell-Like" when a script is written mostly with built-in (cmdlets -and functions)).  Nothing less, nothing more.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Re-inventing the wheel for fun&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Modified mostly "function BackupFolder" part&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style=' color: Green;'&gt;# BackupFiles.ps1&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;# Greg Lyon - July 2006&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;# reference: http://www.microsoft.com/technet/scriptcenter/csc/scripts/backup/backup/cscbk013.mspx&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;# Modified by DBMwS - July 14, 2006&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;param&lt;/span&gt;($strSourceFolder = &lt;span style=' color: Maroon;'&gt;"C:\programming\ps\test"&lt;/span&gt;,&lt;br /&gt;    $strDestinationFolder = &lt;span style=' color: Maroon;'&gt;"F:\backup\programming\ps\test"&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;#{{{ function BackupFolder&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; BackupFolder&lt;br /&gt;{&lt;br /&gt;    param([&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;] $SourceDir = $(throw &lt;span style=' color: Maroon;'&gt;'Enter Source Directory Name'&lt;/span&gt;),&lt;br /&gt;        [&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;] $DestinationDir = $(throw &lt;span style=' color: Maroon;'&gt;'Enter Desitnation Directory Name'&lt;/span&gt;))&lt;br /&gt;&lt;br /&gt;    &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (! (test-path $SourceDir)) {&lt;br /&gt;        throw &lt;span style=' color: Maroon;'&gt;"$($SourceDir) is not a valid directory!"&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;    &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (! (test-path $DestinationDir)) {&lt;br /&gt;        throw &lt;span style=' color: Maroon;'&gt;"$($DestinationDir) is not a valid directory!"&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Check if destination directory is missing any files in the source&lt;/span&gt;&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# directory.if any file is missing, copy them over to the backup dir. &lt;/span&gt;&lt;br /&gt;    get-childitem $SourceDir |&lt;br /&gt;    &lt;span style=' color: Blue;'&gt;foreach&lt;/span&gt; {&lt;br /&gt;        &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; ($_.PsIsContainer) {&lt;br /&gt;            $childDstDir = (join-path $DestinationDir $_.Name)&lt;br /&gt;            &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (! (test-path $childDstDir)) { [&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;](mkdir $childDstDir) }&lt;br /&gt;            BackupFolder $_.FullName $childDstDir&lt;br /&gt;        } &lt;span style=' color: Blue;'&gt;else&lt;/span&gt; {&lt;br /&gt;            $srcFile = $_.FullName&lt;br /&gt;            $destFile = join-path $DestinationDir $_.Name&lt;br /&gt;&lt;br /&gt;            &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (test-path $destFile) {&lt;br /&gt;                $timeDiff = ($srcFile.LastWriteTime - $destFile.LastWriteTime).TotalSeconds&lt;br /&gt;                &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; ($timeDiff -gt &lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;) {&lt;br /&gt;                    copy-item $srcFile $destFile -Force&lt;br /&gt;                    write-host &lt;span style=' color: Maroon;'&gt;"Copied file $($srcFile) to $($destFile)"&lt;/span&gt;&lt;br /&gt;                    $script:iCopyCount++&lt;br /&gt;                }&lt;br /&gt;            } &lt;span style=' color: Blue;'&gt;else&lt;/span&gt; {&lt;br /&gt;                copy-item $srcFile $destFile -Force&lt;br /&gt;                write-host &lt;span style=' color: Maroon;'&gt;"Copied file $($srcFile) to $($destFile)"&lt;/span&gt;&lt;br /&gt;                $script:iCopyCount++&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Check if Source dir is missing any files on the backup dir.&lt;/span&gt;&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# if there is/are file(s) missing, copy them over from backup dir to src dir&lt;/span&gt;&lt;br /&gt;    get-childitem $DestinationDir |&lt;br /&gt;    &lt;span style=' color: Blue;'&gt;foreach&lt;/span&gt; {&lt;br /&gt;        &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; ($_.PsIsContainer) {&lt;br /&gt;            $childSrcDir = (join-path $SourceDir $_.Name)&lt;br /&gt;            &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (! (test-path $childSrcDir)) { [&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;](mkdir $childSrcDir) }&lt;br /&gt;            BackupFolder $childSrcDir $_.FullName&lt;br /&gt;        } &lt;span style=' color: Blue;'&gt;else&lt;/span&gt; {&lt;br /&gt;            $srcFile = join-path $SourceDir $_.Name&lt;br /&gt;            &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (! (test-path $srcFile)) {&lt;br /&gt;                remove-item $_&lt;br /&gt;                write-host &lt;span style=' color: Maroon;'&gt;"Deleted file $($_)"&lt;/span&gt;&lt;br /&gt;                $script:iDestDeletedCount++&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;span style=' color: Green;'&gt;#}}}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;#{{{ function WaitKey&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; WaitKey {&lt;br /&gt;  param( [&lt;span style=' color: Blue;'&gt;String&lt;/span&gt;] $strPrompt = &lt;span style=' color: Maroon;'&gt;"Press any key to continue ... "&lt;/span&gt;)&lt;br /&gt;  Write-Host&lt;br /&gt;  Write-Host $strPrompt -NoNewline&lt;br /&gt;  $key = [Console]::ReadKey($&lt;span style=' color: Maroon;'&gt;true&lt;/span&gt;)&lt;br /&gt;  Write-Host&lt;br /&gt;}&lt;br /&gt;&lt;span style=' color: Green;'&gt;#}}}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;#{{{ MAIN BODY&lt;/span&gt;&lt;br /&gt;$iCopyCount = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;&lt;br /&gt;$iDestDeletedCount = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Write-Host&lt;br /&gt;Write-Host &lt;span style=' color: Maroon;'&gt;"Backing up "&lt;/span&gt; -NoNewline -ForegroundColor &lt;span style=' color: Maroon;'&gt;"White"&lt;/span&gt;&lt;br /&gt;Write-Host $strSourceFolder -ForegroundColor &lt;span style=' color: Maroon;'&gt;"Cyan"&lt;/span&gt; -NoNewline&lt;br /&gt;Write-Host &lt;span style=' color: Maroon;'&gt;" to "&lt;/span&gt; -NoNewline -ForegroundColor &lt;span style=' color: Maroon;'&gt;"White"&lt;/span&gt;&lt;br /&gt;Write-Host $strDestinationFolder -ForegroundColor &lt;span style=' color: Maroon;'&gt;"Cyan"&lt;/span&gt;&lt;br /&gt;Write-Host&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (! (test-path $strSourceFolder)) {&lt;br /&gt;    Write-Host &lt;span style=' color: Maroon;'&gt;"Error: source folder does not exist!"&lt;/span&gt; -ForegroundColor &lt;span style=' color: Maroon;'&gt;"Red"&lt;/span&gt;&lt;br /&gt;    Write-Host&lt;br /&gt;    Write-Host &lt;span style=' color: Maroon;'&gt;"Exiting script"&lt;/span&gt;&lt;br /&gt;    WaitKey &lt;span style=' color: Maroon;'&gt;"Press any key to exit ... "&lt;/span&gt;&lt;br /&gt;    exit&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (! (test-path $strDestinationFolder)) {&lt;br /&gt;    Write-Host &lt;span style=' color: Maroon;'&gt;"Warning: destination folder`($($strDestinationFolder)`) does not exist"&lt;/span&gt;&lt;br /&gt;    $p = Read-Host &lt;span style=' color: Maroon;'&gt;"Create folder and continue? "&lt;/span&gt;&lt;br /&gt;    Write-Host&lt;br /&gt;&lt;br /&gt;    &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; ( $p[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] -ieq &lt;span style=' color: Maroon;'&gt;'y'&lt;/span&gt; ) {&lt;br /&gt;    new-item -Type Directory -Path $strDestinationFolder | out-&lt;span style=' color: Blue;'&gt;null&lt;/span&gt;&lt;br /&gt;  } &lt;span style=' color: Blue;'&gt;else&lt;/span&gt; {&lt;br /&gt;        Write-Host &lt;span style=' color: Maroon;'&gt;"Exiting script"&lt;/span&gt;&lt;br /&gt;        WaitKey &lt;span style=' color: Maroon;'&gt;"Press any key to exit ... "&lt;/span&gt;&lt;br /&gt;        exit&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;BackupFolder $strSourceFolder $strDestinationFolder&lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;if&lt;/span&gt;( ($iCopyCount -eq &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;) -and ($iDestDeletedCount -eq &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;) ) {&lt;br /&gt;  Write-Host&lt;br /&gt;  Write-Host &lt;span style=' color: Maroon;'&gt;"Folders are synchronized"&lt;/span&gt; -ForegroundColor &lt;span style=' color: Maroon;'&gt;"magenta"&lt;/span&gt;&lt;br /&gt;} &lt;span style=' color: Blue;'&gt;else&lt;/span&gt; {&lt;br /&gt;  Write-Host&lt;br /&gt;  Write-Host $iCopyCount &lt;span style=' color: Maroon;'&gt;"files copied from source to destination"&lt;/span&gt; -ForegroundColor &lt;span style=' color: Maroon;'&gt;"magenta"&lt;/span&gt;&lt;br /&gt;  Write-Host $iDestDeletedCount &lt;span style=' color: Maroon;'&gt;"orphaned destination files deleted"&lt;/span&gt; -ForegroundColor &lt;span style=' color: Maroon;'&gt;"magenta"&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;WaitKey &lt;span style=' color: Maroon;'&gt;"Press any key to exit ... "&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;#}}}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-115293328677766190?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/115293328677766190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=115293328677766190' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115293328677766190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115293328677766190'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/07/re-inventing-wheel-for-fun.html' title='Re-inventing the wheel for fun.'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-115151349378448906</id><published>2006-06-28T12:42:00.000-04:00</published><updated>2006-06-28T12:55:32.316-04:00</updated><title type='text'>Windows Desktop Search Powershell Cmdlet by Sean McLeod</title><content type='html'>Great stuff!&lt;br /&gt;A cmdlet, &lt;em&gt;&lt;strong&gt;Get-WDS&lt;/strong&gt;&lt;/em&gt; (in SnapIn) that searches &lt;a href="http://desktop.msn.com/"&gt;WDS(Windows Desktop Search)&lt;/a&gt; indexes is born...&lt;br /&gt;&lt;br /&gt;Mr. Sean McLeod(the author) Newsgroup post on microsoft.public.windows.PowerShell can be found &lt;a href="http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.powershell&amp;mid=d183fd21-ec08-4285-9cb2-f47c8f3ca79a"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Instead of me explaining what the cmdlet is about and how it works, go to &lt;a href="http://www.codeproject.com/"&gt;The Code Project&lt;/a&gt; article, &lt;a href="http://www.codeproject.com/useritems/wdscmdlet.asp"&gt;Windows Desktop Search Powershell Cmdlet&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt; &lt;a href="http://technorati.com/tag/WindowsDesktopSearch" rel="tag"&gt;WindowsDesktopSearch&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-115151349378448906?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/115151349378448906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=115151349378448906' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115151349378448906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115151349378448906'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/06/windows-desktop-search-powershell.html' title='Windows Desktop Search Powershell Cmdlet by Sean McLeod'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-115085520127905245</id><published>2006-06-20T21:39:00.000-04:00</published><updated>2006-06-21T13:04:02.236-04:00</updated><title type='text'>Extending TabExpansion function Part 3</title><content type='html'>&lt;strong&gt;EDIT*: &lt;/strong&gt;According to &lt;a href="http://mow001.blogspot.com"&gt;/\/\o\/\/&lt;/a&gt;'s advice(refer to comment's section), i have modified the previous source to use &lt;em&gt;Get-Help&lt;/em&gt; instead of &lt;em&gt;Get-ChildItem&lt;/em&gt; to retrieve available &lt;em&gt;about_&lt;/em&gt; help file names. (BTW, i will be modifying this script yet, again, so that "about_" would expand only when "Get-Help" or "Help" is already typed...(not to mess up File name expansion in $PsHome directory)&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;  &lt;SPAN style="COLOR: green"&gt;# Handle "about_*" help manuals&lt;/SPAN&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: maroon"&gt;'\s*(about_[\w|\d]*)'&lt;/SPAN&gt; {&lt;br /&gt;    $matched = $matches[&lt;SPAN style="COLOR: maroon"&gt;1&lt;/SPAN&gt;]&lt;br /&gt;    $helpFileNames = &lt;SPAN style="COLOR: blue"&gt;Get-Help&lt;/SPAN&gt; $matched | &lt;SPAN style="COLOR: blue"&gt;Sort-Object&lt;/SPAN&gt; Name | &lt;SPAN style="COLOR: blue"&gt;Select-Object&lt;/SPAN&gt; Name&lt;br /&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($helpFileNames.Length -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) {&lt;br /&gt;      $helpFileNames | &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; { &lt;br /&gt;        &lt;SPAN style="COLOR: green"&gt;# extract manual name(NOTE:same RegEx pattern)&lt;/SPAN&gt;&lt;br /&gt;        $m = [RegEx]::Matches($_.Name, &lt;SPAN style="COLOR: maroon"&gt;'\s*(about_[\w|\d]*)'&lt;/SPAN&gt;)&lt;br /&gt;        $m[&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;].Value&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;In this version, i have added functionality to expand "about_[tab]" manual files.&lt;br /&gt;&lt;br /&gt;Now you can do;&lt;br /&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="FONT-WEIGHT: bold"&gt;about_&lt;/span&gt;&lt;span style="FONT-STYLE: italic"&gt;[Tab]&lt;/span&gt; -&gt; &lt;span style="FONT-WEIGHT: bold"&gt;about_Alias&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="FONT-WEIGHT: bold"&gt;about_r&lt;/span&gt;&lt;span style="FONT-STYLE: italic"&gt;[Tab]&lt;/span&gt; -&gt; &lt;span style="FONT-WEIGHT: bold"&gt;about_regular_expression&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="FONT-WEIGHT: bold"&gt;about_regular_&lt;/span&gt;&lt;span style="FONT-STYLE: italic"&gt;[Tab]&lt;/span&gt; -&gt; &lt;span style="FONT-WEIGHT: bold"&gt;about_regular_expression&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="FONT-WEIGHT: bold"&gt;about_u&lt;/span&gt;&lt;span style="FONT-STYLE: italic"&gt;[Tab]&lt;/span&gt; -&gt; &lt;span style="FONT-WEIGHT: bold"&gt;about_ubiquitous_parameters&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;I was a bit annoyed to type long manual names like &lt;span style="FONT-STYLE: italic"&gt;about_ubiquitous_parameters&lt;/span&gt; and &lt;span style="FONT-STYLE: italic"&gt;about_regular_expression&lt;/span&gt; (which is a manual i read often) all the time so decided to become *lazy*...&lt;br /&gt;&lt;br /&gt;When you do &lt;span style="FONT-STYLE: italic"&gt;get-help about_alias&lt;/span&gt;, &lt;span style="FONT-STYLE: italic"&gt;See Also&lt;/span&gt; section mentions &lt;span style="FONT-STYLE: italic"&gt;about_variable&lt;/span&gt; manual.&lt;br /&gt;If you try "about_v&lt;span style="FONT-STYLE: italic"&gt;[Tab]&lt;/span&gt;" it would not work because there is no manual file named &lt;span style="FONT-STYLE: italic"&gt;about_variable.help.txt&lt;/span&gt; in $pshome.&lt;br /&gt;&lt;br /&gt;Now it should be apparent now how I have implemented my functionality.&lt;br /&gt;It basically checks for manual file name that matches "about_blah*" against manual file names on $PSHOME directory.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:blue;"&gt;switch&lt;/span&gt; -regex ($lastWord)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color:green;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# Other functionalities...&lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# Handle "about_*" help manuals&lt;/span&gt;&lt;br /&gt;&lt;span style="color:maroon;"&gt;'\s*(about_[\w\d]*)'&lt;/span&gt; {&lt;br /&gt; $matched = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;]&lt;br /&gt; &lt;span style="color:green;"&gt;# Search for manual file name in $PSHOME&lt;/span&gt;&lt;br /&gt; $helpFileNames = Get-ChildItem &lt;span style="color:maroon;"&gt;"$pshome/$($matched)*.help.txt"&lt;/span&gt; | Sort-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; Name | Select-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; Name&lt;br /&gt;&lt;br /&gt; &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($helpFileNames -ne $&lt;span style="color:blue;"&gt;null&lt;/span&gt;) {&lt;br /&gt;   $helpFileNames  &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {&lt;br /&gt;     &lt;span style="color:green;"&gt;# extract manual name(NOTE:same RegEx pattern)&lt;/span&gt;&lt;br /&gt;     $m = [RegEx]::Matches($_.Name, &lt;span style="color:maroon;"&gt;'\s*(about_[\w\d]*)'&lt;/span&gt;)&lt;br /&gt;     $m[&lt;span style="color:maroon;"&gt;0&lt;/span&gt;].Value&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# ...&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;Add above piece of code to "TabExpansion.ps1", go to wherever you have saved the file and ". .\TabExpansion.ps1" and you are good to go.&lt;br /&gt;For previous blog posts(mine or &lt;a href="http://mow001.blogspot.com"&gt;/\/\o\/\/&lt;/a&gt;'s)on "TabExpansion", go check out "&lt;a href="http://del.icio.us/powershell/TabExpansion"&gt;http://del.icio.us/powershell/TabExpansion&lt;/a&gt;"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-115085520127905245?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/115085520127905245/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=115085520127905245' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115085520127905245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115085520127905245'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/06/extending-tabexpansion-function-part-3.html' title='Extending TabExpansion function Part 3'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-115033631867249059</id><published>2006-06-14T21:47:00.000-04:00</published><updated>2006-06-15T10:22:21.033-04:00</updated><title type='text'>Domain Names</title><content type='html'>&lt;strong&gt;EDIT*:&lt;/strong&gt; great, both domains are working properly~&lt;br /&gt;&lt;br /&gt;Uhm, Just bought two domain names.&lt;br /&gt;Here is how I will forward my new domains.&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.PsObject.com"&gt;PsObject.com&lt;/a&gt;: to this current blog site.(&lt;a href="http://monadblog.blogspot.com"&gt;http://monadblog.blogspot.com&lt;/a&gt;)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.PsObject.net"&gt;PsObject.net&lt;/a&gt;: to &lt;a href="http://del.icio.us/powershell"&gt;del.icio.us/powershell&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;They are easier to remember &amp;&amp;amp; type(as well as names being shorter...)&lt;br /&gt;I think it will take about 2 ~ 3 days for them to take effect...&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-115033631867249059?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/115033631867249059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=115033631867249059' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115033631867249059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115033631867249059'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/06/domain-names.html' title='Domain Names'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-115025176229621943</id><published>2006-06-13T20:10:00.000-04:00</published><updated>2006-06-13T22:25:38.560-04:00</updated><title type='text'>Getting Services associated with a Process via PowerShell (.NET Type Extension)</title><content type='html'>On a recent &lt;a href="http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.powershell"&gt;Microsoft.Public.Windows.PowerShell&lt;/a&gt; NG (Newsgroup) posts, Andrew Watt has asked for an "&lt;a href="http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.powershell&amp;mid=453f2394-e30f-4ee8-a071-ab99233ce2f5"&gt;Equivalent [cmdlet] for tasklist /svc&lt;/a&gt;".&lt;br /&gt;&lt;br /&gt;Luckily, &lt;a href="http://abhishek225.spaces.msn.com/PersonalSpace.aspx"&gt;Abhishek&lt;/a&gt; has posted a blog entry concerning that very problem a couple of weeks ago as "&lt;a href="http://abhishek225.spaces.msn.com/blog/cns%2113469C7B7CE6E911%21140.entry?txtName=DBMwS&amp;amp;blogcs=end"&gt;Getting Services associated with a Process via PowerShell&lt;/a&gt;" on May 18, 2006.&lt;br /&gt;&lt;br /&gt;According to Abhishek, "the Cmdlet implementation relies on &lt;span style="font-style: italic;"&gt;System.Diagnostics.Process&lt;/span&gt; class in .Net  which unfortunately does not expose this information", so he has utilized WMI object  &lt;span style="font-style: italic;"&gt;Win32_Service&lt;/span&gt;  to retrieve service information associated with a process.&lt;br /&gt;&lt;br /&gt;Abhishek has approached to the problem with a function, &lt;span style="font-style: italic;"&gt;plist&lt;/span&gt;, to iterate each &lt;span style="font-style: italic;"&gt;System.Diagnostics.Process&lt;/span&gt; object instance type and match each process against service information retreived through &lt;span style="font-style: italic;"&gt;Win32_Service&lt;/span&gt;, and the append a NoteProprety to each "System.Diagnostics.Process" object instances.&lt;br /&gt;&lt;br /&gt;But then, I just wanted more intuitive way(well i just wanted to mess around...) to retrieve "Service" information associated with a process id and .. Ta~da~...  There was &lt;span style="font-weight: bold; font-style: italic;"&gt;types.ps1xml&lt;/span&gt;...&lt;br /&gt;One of the beauties of PowerShell is that, you can extend .NET types as you want.  (Anyways, for more links concerning Type Extension feature and articles, go to &lt;a href="http://del.icio.us/powershell/TypeExtension"&gt;http://del.icio.us/powershell/TypeExtension&lt;/a&gt;...)&lt;br /&gt;&lt;br /&gt;This time, I have yet again, tried to extend another .NET type, &lt;span style="font-style: italic;"&gt;System.Diagnostics.Process&lt;/span&gt; as I did in previous post(&lt;span class="PostTitle"&gt;  &lt;a href="http://monadblog.blogspot.com/2006/04/msh-extending-systemsecuritysecurestri.html"&gt;[MSH] Extending System.Security.SecureString&lt;/a&gt; ).&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:Blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:Maroon;"&gt;Type&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color:Maroon;"&gt;Name&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;System.Diagnostics.Process&lt;span style="color:Blue;"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color:Maroon;"&gt;Name&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color:Maroon;"&gt;Members&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   ... Other membersets and properties ...&lt;br /&gt;&lt;span style="color:Blue;"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color:Maroon;"&gt;ScriptProperty&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color:Maroon;"&gt;Name&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;Service&lt;span style="color:Blue;"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color:Maroon;"&gt;Name&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color:Maroon;"&gt;GetScriptBlock&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       $svc = @(, (Get-WmiObject Win32_Service -Filter "&lt;span style="color:Blue;"&gt;ProcessId='$($this.Id)'&lt;/span&gt;" | Group-Object ProcessId).Group)&lt;br /&gt;       if ($svc[0] -eq $null) { "&lt;span style="color:Blue;"&gt;N/A&lt;/span&gt;" } else { $svc }&lt;br /&gt;&lt;span style="color:Blue;"&gt;      &amp;lt;&lt;/span&gt;/&lt;span style="color:Maroon;"&gt;GetScriptBlock&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;    &amp;lt;&lt;/span&gt;/&lt;span style="color:Maroon;"&gt;ScriptProperty&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &amp;lt;&lt;/span&gt;/&lt;span style="color:Maroon;"&gt;Members&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color:Maroon;"&gt;Type&lt;/span&gt;&lt;span style="color:Blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Ok, now let's see. What's going on here?&lt;br /&gt;In $pshome\&lt;span style="font-style: italic;"&gt;types.ps1xml&lt;/span&gt;, I am extending &lt;span style="font-style: italic;"&gt;System.Diagnostics.Process&lt;/span&gt; type (&lt;name&gt;System.Diagnostics.Process&lt;/name&gt;) to include a &lt;span style="font-style: italic;"&gt;ScriptProperty&lt;/span&gt; (&lt;scriptproperty&gt;) which contains a script block (&lt;getscriptblock&gt;) to retrieve Service information associated with current Process's id (&lt;span style="font-style: italic;"&gt;$this.Id&lt;/span&gt;) from Win32_Service WMI object.&lt;br /&gt;&lt;br /&gt;The reason I have added the "if" statement on the second line in &lt;span style="font-style: italic;"&gt;&lt;getscriptblock&gt;&lt;/getscriptblock&gt;&lt;/span&gt; is because when you run "&lt;span style="font-style: italic;"&gt;tasklist /svc&lt;/span&gt;", if there is no service(s) associated with a process ID, it is returned as "N/A".&lt;br /&gt;&lt;br /&gt;There are two gotchas, here that you have to be careful of.&lt;br /&gt;&lt;/getscriptblock&gt;&lt;/scriptproperty&gt;&lt;ol&gt;&lt;li style="font-style: italic;"&gt;&lt;pre&gt;$svc = @(, (Get-WmiObject ...&lt;/pre&gt;&lt;/li&gt;&lt;li style="font-style: italic;"&gt;&lt;pre&gt;if ($svc[0] ...&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;For the first case, I am actually including a null object to force an array with one item to be interpreted as an array with multiple items.&lt;br /&gt;To illustrate the point, let's see the following case.&lt;br /&gt;&lt;blockquote&gt;[^_^]PS[142]&gt;$a = @(1)&lt;br /&gt;[^_^]PS[143]&gt;$a | Get-Member&lt;br /&gt;TypeName: System.Int32&lt;br /&gt;Name        MemberType Definition&lt;br /&gt;----        ---------- ----------&lt;br /&gt;CompareTo   Method     System.Int32 Compa&lt;br /&gt;...&lt;br /&gt;[^_^]PS[144]&gt;, $a | Get-Member&lt;br /&gt;TypeName: System.Object[]&lt;br /&gt;...&lt;/blockquote&gt;Although I have declared &lt;span style="font-style: italic;"&gt;$a&lt;/span&gt; as an array of one item, "Get-Member" will return "System.Int32" , which is the type of the array item(1), as its TypeName for $a although most of people would expect an array type to be returned.  Anyways,  there was this NG post or a blog entry that dealt with this problem and I will try to update the blog later on for links concerning this problem.&lt;br /&gt;&lt;br /&gt;For the second problem, well, I was checking for "&lt;span style="font-style: italic;"&gt;$svc.Length -lt 1&lt;/span&gt;" but it turns out that, &lt;span style="font-style: italic;"&gt;$svc.Length&lt;/span&gt; is always equal to or great than 1 because $svc will always contain a null object.(this is not that clear of an explanation... since I haven't understood this clearly, yet)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Why did I even bother going through the gotchas?&lt;br /&gt;Well,  if i hadn't used "@(, (Get-Wmi..." and used just "@(Get-Wmi..." then what you might get is something as ugly as&lt;br /&gt;&lt;span id="ctl03_lblPermalink"&gt;&lt;span id="commentseccns!13469C7B7CE6E911!140"&gt;&lt;p&gt;&lt;/p&gt;&lt;blockquote&gt;[^_^]PS[10]&gt;gps svchost | select name,id,service | ft -auto&lt;br /&gt;&lt;br /&gt;Name      Id Service&lt;br /&gt;----      -- -------&lt;br /&gt;SVCHOST  972 {DcomLaunch, TermService}&lt;br /&gt;SVCHOST 1072 \\IT03\root\cimv2:Win32_Service.Name="RpcSs"&lt;br /&gt;SVCHOST 1204 \\IT03\root\cimv2:Win32_Service.Name="Dnscache"&lt;br /&gt;SVCHOST 1264 {Alerter, LmHosts, SSDPSRV, WebClient}&lt;br /&gt;SVCHOST 1284 {AppMgmt, AudioSrv, BITS, Browser...}&lt;br /&gt;SVCHOST 3540 \\IT03\root\cimv2:Win32_Service.Name="stisvc"&lt;br /&gt;SVCHOST 3772 \\IT03\root\cimv2:Win32_Service.Name="usnsvc"&lt;/blockquote&gt;&lt;p&gt;where you see a full type name for &lt;span style="font-style: italic;"&gt;Service property&lt;/span&gt; with only ONE service associated thereof.&lt;/p&gt;&lt;/span&gt;&lt;/span&gt;The reason for the "&lt;span style="font-style: italic;"&gt;if&lt;/span&gt;" is hmm well, if you run "&lt;span style="font-style: italic;"&gt;tasklist /svc&lt;/span&gt;", for process Id's with no associated service(s), it returns "N/A" so I just wanted to mimic the behavior...&lt;br /&gt;&lt;br /&gt;Well, that's it folks...&lt;br /&gt;Ah, lastly, I have to tell you that running "Get-Process | Select-Object name,id,service" takes quite a long time(about 4 seconds!!! compared to 0.3 &amp; 0.2 seconds by "tasklist /svc" and "plist" function).  It is defniately &lt;span style="font-style: italic; font-weight: bold;"&gt;not&lt;/span&gt; an efficient way to retrieve Service information associated with a process id.  Extend your type and have fun at your own risk... ;)&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;[^_^]PS[2]&gt;Measure-Command { Get-Process | Select-Object name,id,service }&lt;br /&gt;&lt;br /&gt;Days              : 0&lt;br /&gt;Hours             : 0&lt;br /&gt;Minutes           : 0&lt;br /&gt;Seconds           : 4&lt;br /&gt;Milliseconds      : 198&lt;br /&gt;Ticks             : 41988791&lt;br /&gt;TotalDays         : 4.85981377314815E-05&lt;br /&gt;TotalHours        : 0.00116635530555556&lt;br /&gt;TotalMinutes      : 0.0699813183333333&lt;br /&gt;TotalSeconds      : 4.1988791&lt;br /&gt;TotalMilliseconds : 4198.8791&lt;br /&gt;&lt;br /&gt;[^_^]PS[3]&gt;Measure-Command { tasklist /svc }&lt;br /&gt;&lt;br /&gt;Days              : 0&lt;br /&gt;Hours             : 0&lt;br /&gt;Minutes           : 0&lt;br /&gt;Seconds           : 0&lt;br /&gt;Milliseconds      : 244&lt;br /&gt;Ticks             : 2440259&lt;br /&gt;TotalDays         : 2.82437384259259E-06&lt;br /&gt;TotalHours        : 6.77849722222222E-05&lt;br /&gt;TotalMinutes      : 0.00406709833333333&lt;br /&gt;TotalSeconds      : 0.2440259&lt;br /&gt;TotalMilliseconds : 244.0259&lt;br /&gt;&lt;br /&gt;[^_^]PS[4]&gt;Measure-Command { plist * | Format-Table name,id,service }&lt;br /&gt;&lt;br /&gt;Days              : 0&lt;br /&gt;Hours             : 0&lt;br /&gt;Minutes           : 0&lt;br /&gt;Seconds           : 0&lt;br /&gt;Milliseconds      : 341&lt;br /&gt;Ticks             : 3419322&lt;br /&gt;TotalDays         : 3.95754861111111E-06&lt;br /&gt;TotalHours        : 9.49811666666667E-05&lt;br /&gt;TotalMinutes      : 0.00569887&lt;br /&gt;TotalSeconds      : 0.3419322&lt;br /&gt;TotalMilliseconds : 341.9322&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-115025176229621943?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/115025176229621943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=115025176229621943' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115025176229621943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115025176229621943'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/06/getting-services-associated-with.html' title='Getting Services associated with a Process via PowerShell (.NET Type Extension)'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-115005514128868794</id><published>2006-06-11T15:12:00.000-04:00</published><updated>2006-06-13T22:31:34.543-04:00</updated><title type='text'>"Prompt" function</title><content type='html'>&lt;span style="font-weight: bold;"&gt;EDIT2*:&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;/span&gt;Well, That weird out-of-order registration of commands in history is not so funky any more after reading Bruce Payette's &lt;a href="http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.powershell&amp;mid=14ceb3c4-0a46-4e33-9e48-4fcaae14daa1"&gt;post&lt;/a&gt; on &lt;a href="http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.windows.powershell"&gt;Microsoft.Public.Windows.PowerShell NG&lt;/a&gt;...&lt;br /&gt;"&lt;span style="font-style: italic;"&gt;Command that's creating a nested prompt level is complete only after you exit the nested level&lt;/span&gt;"...&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;EDIT*:&lt;/span&gt; This is kind of funky...&lt;br /&gt;&lt;a href="http://photobucket.com" target="_blank"&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/powershell/FunkyHistory.gif" alt="Photobucket - Video and Image Hosting" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;When you look at the output of &lt;span style="font-style: italic;"&gt;Get-History&lt;/span&gt; in the 6th prompt, &lt;span style="font-style: italic;"&gt;Start-NewScope&lt;/span&gt; are registered into history &lt;span style="font-weight: bold;"&gt;after&lt;/span&gt; &lt;span style="font-style: italic;"&gt;Exit&lt;/span&gt;... and moreover, after each &lt;span style="font-style: italic;"&gt;Exit&lt;/span&gt;, history counts have incremented by 2 instead of 1...&lt;br /&gt;&lt;br /&gt;Uhm, I am kind of bored so I am gonna just post my "Prompt" function source in my "Profile.Ps1".&lt;br /&gt;I have 3 parts in my PowerShell prompt&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Nested Prompt Level(&lt;span style="color: rgb(51, 51, 255);"&gt;[^_^]&lt;/span&gt; &lt;- when the nested prompt level is "0")&lt;/li&gt;&lt;li&gt;"PS" in red(Uhm, I forgot where i saw that flashy red &lt;span style="color: rgb(255, 0, 0);"&gt;MSH&lt;/span&gt;&gt; Prompt last year for the first time...)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;History Count(&lt;span style="color: rgb(102, 255, 255);"&gt;[2]&lt;/span&gt;, not count of last history but the history count of what you will run)&lt;/li&gt;&lt;/ol&gt;Here is the screenshot of my prompt&lt;br /&gt;&lt;br /&gt;&lt;a href="http://photobucket.com" target="_blank"&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/powershell/history.gif" alt="Photobucket - Video and Image Hosting" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have found history count(refer to Lee Holmes' blog on "&lt;a href="http://www.leeholmes.com/blog/AHistoryBrowsingPrompt.aspx"&gt;A History Browsing Prompt&lt;/a&gt;" for extracting history count, there are few quirks here and there.) to be quite useful as I find myself copying and pasting from console and history(by the way, check out How &lt;a href="http://spaces.msn.com/KeithHill"&gt;Keith Hill&lt;/a&gt; got around the problem with a &lt;a href="http://spaces.msn.com/keithhill/blog/cns%215A8D2641E0963A97%21320.entry?_c11_blogpart_blogpart=blogview&amp;_c=blogpart#permalink"&gt;SelectHistory &lt;/a&gt;script)&lt;br /&gt;&lt;br /&gt;Below is my "Prompt" function and "Start-NewScope"(function invoked on the screenshot) can be found on PowerShell Team blog http://blogs.msdn.com/monad/archive/2006/04/15/576996.aspx&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:Green;"&gt;# reference: For History Count, &lt;/span&gt;&lt;br /&gt;&lt;span style="color:Green;"&gt;# Author: DBMwS&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Green;"&gt;#    http://www.leeholmes.com/blog/CommentView,guid,0a552b85-2abe-4528-be41-d55762eb41de.aspx&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Green;"&gt;#     and Jeffrey Snover's comment on NG for nested prompt(or Start-NewScope)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;function&lt;/span&gt; prompt&lt;br /&gt;{&lt;br /&gt;&lt;span style="color:Blue;"&gt;  if&lt;/span&gt; (($NestedPromptLevel -eq $&lt;span style="color:Blue;"&gt;null&lt;/span&gt;) -or ($NestedPromptLevel -eq &lt;span style="color:Maroon;"&gt;0&lt;/span&gt;)) {&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;# I want to see more friendly Prompt... so chose "^_^" over "0"&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;$private:level = &lt;span style="color:Maroon;"&gt;"^_^"&lt;/span&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;} &lt;span style="color:Blue;"&gt;else&lt;/span&gt; { $private:level = $NestedPromptLevel }&lt;br /&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;$private:h = @(Get-History)&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;$private:nextCommand = $private:h[$private:h.Count - &lt;span style="color:Maroon;"&gt;1&lt;/span&gt;].Id + &lt;span style="color:Maroon;"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;Write-Host -NoNewline -ForeGroundColor Blue [$private:level]&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;Write-Host -NoNewline -ForeGroundColor Red PS;&lt;br /&gt;&lt;span style="color:Blue;"&gt;  &lt;/span&gt;Write-Host -NoNewLine -ForeGroundColor Cyan [$private:nextCommand]; &lt;span style="color:Maroon;"&gt;"&amp;gt;"&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I would like to address why i am checking for &lt;span style="font-style: italic;"&gt;($NestedPromptLevel -eq $null) &lt;/span&gt;in the "if" statement(According to Jeffrey Snover, "&lt;a href="http://blogs.msdn.com/monad/archive/2006/04/15/576996.aspx"&gt;BTW - every time you enter a nested prompt, $NESTEDPROMPTLEVEL is incremented so I include this information in my prompt&lt;/a&gt;", but I could find out about it on "get-help about_automatic_variables", thought).&lt;br /&gt;&lt;br /&gt;At the time I wrote this function(I am sorry.  I have to admit that I almost blatantly copied and pasted from Lee Holmes' blog...), when the powershell started, $NestedPromptLevel was set to a null instead of "0" but I think it seems to have been fixed in RC1 Update.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://mshforfun.blogspot.com"&gt;Tony&lt;/a&gt; (Msh For Fun) has a &lt;a href="http://mshforfun.blogspot.com/2006/05/perfect-prompt-for-windows-powershell.html"&gt;blog entry&lt;/a&gt; on how to modify your &lt;span style="font-style: italic; font-weight: bold;"&gt;prompt&lt;/span&gt; function the way you like it(like displaying time, and colorizing your prompt, evening randomizing prompt the color...) and &lt;span style="font-weight: bold;"&gt;what&lt;/span&gt; Prompt function is about and &lt;span style="font-weight: bold;"&gt;why&lt;/span&gt; you should bother at all... Great stuff.~&lt;br /&gt;&lt;br /&gt;Prompt related links can be found on &lt;a href="http://del.icio.us/powershell/Prompt"&gt;http://del.icio.us/powershell/Prompt&lt;/a&gt;(I have only 3 links so far but I will be tagging more later on.)&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-115005514128868794?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/115005514128868794/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=115005514128868794' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115005514128868794'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/115005514128868794'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/06/prompt-function.html' title='&quot;Prompt&quot; function'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114982609040723771</id><published>2006-06-08T23:41:00.000-04:00</published><updated>2006-06-11T14:33:33.296-04:00</updated><title type='text'>Extending TabExpansion function Part 2</title><content type='html'>&lt;strong&gt;EDIT2*:&lt;/strong&gt;Pastebin.com site's been down for a while so pasted the colorized source on the bottom...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EDIT*:&lt;/strong&gt; Modified the source a bit but no functional changes made&lt;br /&gt;Simply changed name of Script variables(&lt;em&gt;$_Method, $_ScopeNames&lt;/em&gt;) in "begin" blocks to &lt;em&gt;$Script:Method&lt;/em&gt; and &lt;em&gt;$Script:ScopeNames&lt;/em&gt; respectively according Mow's suggestion.&lt;br /&gt;It can be found &lt;a href="http://powershell.pastebin.com/770310"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;On completion of &lt;a href="http://mow001.blogspot.com/2006/06/powershell-tab-completion-part-4.html"&gt;PowerShell Tab Completion Part 4&lt;/a&gt;, &lt;a href="http://mow001.blogspot.com"&gt;/\/\o\/\/&lt;/a&gt; has suggested me that I should do multilevel scoped variable completion.&lt;br /&gt;&lt;br /&gt;I had to cheat a bit by taking Mow's piece of code and turning it into a function for a reuse.&lt;br /&gt;The source is on &lt;a href="http://powershell.pastebin.com/770310"&gt;PowerShell.Pastebin.com&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;In my version of TabCompletion, Mow's Multilevel variable completion functionality is in a function called "MultiLevelPropertyExpansion" in "begin" block.&lt;br /&gt;Since list of functionalities are listed on &lt;a href="http://mow001.blogspot.com/2006/06/powershell-tab-completion-part-4.html"&gt;PowerShell Tab Completion Part 4&lt;/a&gt; already, I will just mention one tiny improvement.&lt;br /&gt;&lt;br /&gt;In previous version, tab expansion occurred only on the first level&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$global:Host.&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;U&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab] -&gt; &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;$global:Host&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$global:Host.UI.R&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab] -&gt; &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;$global:Host.UI&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But now, multi-level expansion works, as well for scoped variables&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;$global:Host.&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;u&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab] -&gt; &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;$global:Host.UI&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$global:Host.UI.r&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab] -&gt; &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;$global:Host.UI.RawUI&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$global:hos&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;.&lt;span style="font-weight: bold;"&gt;u&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;.&lt;span style="font-weight: bold;"&gt;r&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;.&lt;span style="font-weight: bold;"&gt;g&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt; -&gt; &lt;span style="font-weight: bold;"&gt;$global:Host.UI.RawUI.get_BackgroundColor(&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Uhm, "TabExpansion.ps1"&lt;br /&gt;&lt;pre&gt;&lt;span style="color:green;"&gt;# TabExpansion.ps1&lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# Version 0.4&lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# Replacement of default TabExpansion function&lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# /\/\o\/\/ 2006&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;function&lt;/span&gt; TabExpansion {&lt;br /&gt;   &lt;span style="color:green;"&gt;# This is the default function that gets called for tab expansion.&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# Edited by /\/\o\/\/ from the original to handle :&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;#  - Cached tab completion on types (janel / mow).&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;#  - Methods and properties of types&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;#  - shows get_ methods&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;#  - MultiLevel variable Tab Completion&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;#  - Bracet Removal&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# Edited by DBMwS: Added Progressbar and Scoped variable name expansion&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;#  - MultiLevel variable Tab Completion for Scoped variables&lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;   #  - Changed $_* variables to $Script:*&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;param($line, $lastWord)&lt;br /&gt;&lt;br /&gt;begin {&lt;br /&gt; $Script:Method = [Management.Automation.PSMemberTypes] `&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'Method,CodeMethod,ScriptMethod,ParameterizedProperty'&lt;/span&gt;&lt;br /&gt; $Script:ScopeNames = @(&lt;span style="color:maroon;"&gt;"global"&lt;/span&gt;, &lt;span style="color:maroon;"&gt;"local"&lt;/span&gt;, &lt;span style="color:maroon;"&gt;"script"&lt;/span&gt;, &lt;span style="color:maroon;"&gt;"private"&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt; &lt;span style="color:blue;"&gt;function&lt;/span&gt; MultiLevelPropertyExpansion {&lt;br /&gt;  param($parent, $child)&lt;br /&gt;&lt;br /&gt;  $private:explodedChild = $child.split(&lt;span style="color:maroon;"&gt;'.'&lt;/span&gt;)&lt;br /&gt;  $private:level = $explodedChild.Count&lt;br /&gt;  $private:value = $parent&lt;br /&gt;  &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($private:level -gt &lt;span style="color:maroon;"&gt;1&lt;/span&gt;) {&lt;br /&gt;   $private:value += &lt;span style="color:maroon;"&gt;".$($explodedChild[0..($level - 2)])"&lt;/span&gt;&lt;br /&gt;  }&lt;br /&gt;  $private:pattern = $private:explodedChild[($level -&lt;span style="color:maroon;"&gt;1&lt;/span&gt;)] + &lt;span style="color:maroon;"&gt;'*'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# /\/\o\/\/ removed : -and $n -notmatch '^[ge]et_'&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# to get get_ methods on WMI and AD objects&lt;/span&gt;&lt;br /&gt;  $private:result = @()&lt;br /&gt;  $private:inputObject = &lt;span style="color:maroon;"&gt;'$'&lt;/span&gt; + $private:value&lt;br /&gt;  invoke-expression &lt;span style="color:maroon;"&gt;"Get-Member -InputObject $inputObject"&lt;/span&gt; |&lt;br /&gt;  Sort-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; name | &lt;span style="color:blue;"&gt;where&lt;/span&gt; {$_.name -like $pattern } |&lt;br /&gt;  &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {&lt;br /&gt;   $private:result += @{&lt;br /&gt;    MemberType = $_.MemberType;&lt;br /&gt;    Name = $_.Name;&lt;br /&gt;    Value = $private:value;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;return&lt;/span&gt; $private:result&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;process {&lt;br /&gt; &lt;span style="color:blue;"&gt;switch&lt;/span&gt; -regex ($lastWord)&lt;br /&gt; {&lt;br /&gt;  &lt;span style="color:green;"&gt;# Handle methods of Types (/\/\o\/\/).&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# E.g.) [DateTime]::F[tab]&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'(\[.*\])::(\w*)'&lt;/span&gt; {&lt;br /&gt;   invoke-expression &lt;span style="color:maroon;"&gt;"$($matches[1]) | gm -static"&lt;/span&gt; |&lt;br /&gt;   &lt;span style="color:blue;"&gt;where&lt;/span&gt; { $n = $_.Name;&lt;br /&gt;    $n -like &lt;span style="color:maroon;"&gt;"$($matches[2])*"&lt;/span&gt; -and `&lt;br /&gt;    $n -notmatch &lt;span style="color:maroon;"&gt;'^([gs]et|op)_'&lt;/span&gt;} |&lt;br /&gt;   &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {&lt;br /&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($_.MemberType -band $Script:Method) {&lt;br /&gt;     &lt;span style="color:maroon;"&gt;"$($matches[1])::$($_.name)"&lt;/span&gt; + &lt;span style="color:maroon;"&gt;'('&lt;/span&gt;&lt;br /&gt;    } &lt;span style="color:blue;"&gt;Else&lt;/span&gt; {&lt;br /&gt;     &lt;span style="color:maroon;"&gt;"$($matches[1])::$($_.name)"&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# Remove Brackets from typename (/\/\o\/\/)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'(\[.*\])=(\w*)'&lt;/span&gt; {&lt;br /&gt;   &lt;span style="color:maroon;"&gt;"$($matches[1].replace('[','').replace(']',''))"&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# Cache and Handle namespace and TypeNames (/\/\o\/\/) ..&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'\[(.*)'&lt;/span&gt; {&lt;br /&gt;   $matched = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;]&lt;br /&gt;   &lt;span style="color:green;"&gt;# only the first time Fill a DataTable with&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# Typenames,namespaces and dotCount (level)&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;if&lt;/span&gt; (!($global:dtAssemblies)) {&lt;br /&gt;    $global:dtAssemblies = New-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; System.Data.Datatable&lt;br /&gt;    [&lt;span style="color:blue;"&gt;void&lt;/span&gt;]($global:dtAssemblies.Columns.Add(&lt;span style="color:maroon;"&gt;'name'&lt;/span&gt;,[&lt;span style="color:blue;"&gt;string&lt;/span&gt;]))&lt;br /&gt;    [&lt;span style="color:blue;"&gt;void&lt;/span&gt;]($global:dtAssemblies.Columns.Add(&lt;span style="color:maroon;"&gt;'DC'&lt;/span&gt;,[&lt;span style="color:blue;"&gt;int&lt;/span&gt;]))&lt;br /&gt;    [&lt;span style="color:blue;"&gt;void&lt;/span&gt;]($global:dtAssemblies.Columns.Add(&lt;span style="color:maroon;"&gt;'NS'&lt;/span&gt;,[&lt;span style="color:blue;"&gt;string&lt;/span&gt;]))&lt;br /&gt;    $assemblies = [appdomain]::CurrentDomain.GetAssemblies()&lt;br /&gt;    [&lt;span style="color:blue;"&gt;void&lt;/span&gt;] ($assemblies | % {$i = &lt;span style="color:maroon;"&gt;0&lt;/span&gt;} {&lt;br /&gt;     $i++;&lt;br /&gt;     [&lt;span style="color:blue;"&gt;int&lt;/span&gt;]$assemblyProgress =&lt;br /&gt;      ($i * &lt;span style="color:maroon;"&gt;100&lt;/span&gt;) / $assemblies.Length&lt;br /&gt;     Write-Progress Caching &lt;span style="color:maroon;"&gt;"$assemblyProgress"&lt;/span&gt; `&lt;br /&gt;      -perc $assemblyProgress&lt;br /&gt;&lt;br /&gt;     $types = $_.GetTypes()&lt;br /&gt;     $types |&lt;br /&gt;     &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {$j = &lt;span style="color:maroon;"&gt;0&lt;/span&gt;} {&lt;br /&gt;      $j++;&lt;br /&gt;      &lt;span style="color:blue;"&gt;if&lt;/span&gt; (($j % &lt;span style="color:maroon;"&gt;500&lt;/span&gt;) -eq &lt;span style="color:maroon;"&gt;0&lt;/span&gt;) {&lt;br /&gt;       [&lt;span style="color:blue;"&gt;int&lt;/span&gt;]$typeProgress = ($j * &lt;span style="color:maroon;"&gt;100&lt;/span&gt;) / $types.Length&lt;br /&gt;       Write-Progress &lt;span style="color:maroon;"&gt;"Adding types"&lt;/span&gt; &lt;span style="color:maroon;"&gt;"$typeProgress"&lt;/span&gt; `&lt;br /&gt;        -perc $typeProgress -id &lt;span style="color:maroon;"&gt;1&lt;/span&gt;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      $dc = $_.fullName.split(&lt;span style="color:maroon;"&gt;"."&lt;/span&gt;).count - &lt;span style="color:maroon;"&gt;1&lt;/span&gt;&lt;br /&gt;      $ns = $_.namespace&lt;br /&gt;      $global:dtAssemblies.rows.add(&lt;span style="color:maroon;"&gt;"$_"&lt;/span&gt;,$dc,$ns)&lt;br /&gt;     }&lt;br /&gt;     Write-Progress &lt;span style="color:maroon;"&gt;"Adding types"&lt;/span&gt; &lt;span style="color:maroon;"&gt;"100"&lt;/span&gt; -perc &lt;span style="color:maroon;"&gt;100&lt;/span&gt; -id &lt;span style="color:maroon;"&gt;1&lt;/span&gt;&lt;br /&gt;    })&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# actual tab completion&lt;/span&gt;&lt;br /&gt;   $dots = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;].split(&lt;span style="color:maroon;"&gt;"."&lt;/span&gt;).count - &lt;span style="color:maroon;"&gt;1&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;switch&lt;/span&gt; ($dots) {&lt;br /&gt;    &lt;span style="color:maroon;"&gt;0&lt;/span&gt; {&lt;span style="color:maroon;"&gt;"[System"&lt;/span&gt;,&lt;span style="color:maroon;"&gt;"[Microsoft"&lt;/span&gt;}&lt;br /&gt;    Default {&lt;br /&gt;     $res = @()&lt;br /&gt;     $res += $global:dtAssemblies.select(&lt;br /&gt;      &lt;span style="color:maroon;"&gt;"ns like '$($matched)%' and dc = $($dots + 1)"&lt;/span&gt;) |&lt;br /&gt;       Select-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; -Unique ns |&lt;br /&gt;       &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {&lt;span style="color:maroon;"&gt;"[$($_.ns)"&lt;/span&gt;};&lt;br /&gt;     $res += $global:dtAssemblies.select(&lt;br /&gt;      &lt;span style="color:maroon;"&gt;"name like '$($matched)%' and dc = $dots"&lt;/span&gt;) |&lt;br /&gt;       &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {&lt;span style="color:maroon;"&gt;"[$($_.name)]"&lt;/span&gt;}&lt;br /&gt;     $res&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# Handle property and method expansion (MultiLevel added /\/\o\/\/)...&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'\$(\w+)\.(.*)'&lt;/span&gt; {&lt;br /&gt;   &lt;span style="color:green;"&gt;# parent variable name e.g.) $host.ui.-&amp;gt; parent is "host"&lt;/span&gt;&lt;br /&gt;   $parent = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;];&lt;br /&gt;   &lt;span style="color:green;"&gt;# child variable name e.g.) $host.ui.rawui-&amp;gt; child is "ui.rawui"&lt;/span&gt;&lt;br /&gt;   $child = $matches[&lt;span style="color:maroon;"&gt;2&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;   MultiLevelPropertyExpansion $parent $child |&lt;br /&gt;   &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {&lt;br /&gt;    $output = &lt;span style="color:maroon;"&gt;"$"&lt;/span&gt; + $_[&lt;span style="color:maroon;"&gt;"Value"&lt;/span&gt;] + &lt;span style="color:maroon;"&gt;'.'&lt;/span&gt; + $_[&lt;span style="color:maroon;"&gt;"Name"&lt;/span&gt;]&lt;br /&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($_[&lt;span style="color:maroon;"&gt;"MemberType"&lt;/span&gt;] -band $Script:Method) { $output += &lt;span style="color:maroon;"&gt;"("&lt;/span&gt; }&lt;br /&gt;    &lt;span style="color:blue;"&gt;return&lt;/span&gt; $output&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# Handle expansions for both "Scope Variable Name"&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# and "Type Variable Names" (DbmwS)&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'(.*^\$)(\w+):(\w+)(\.(.*))*$'&lt;/span&gt; {&lt;br /&gt;   &lt;span style="color:green;"&gt;# "function", "variable", "alias", "env:", etc...&lt;/span&gt;&lt;br /&gt;   $type = $matches[&lt;span style="color:maroon;"&gt;2&lt;/span&gt;];&lt;br /&gt;   &lt;span style="color:green;"&gt;# E.g.) '$' + 'function'&lt;/span&gt;&lt;br /&gt;   $prefix = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;] + $type;&lt;br /&gt;   &lt;span style="color:green;"&gt;# e.g. in '$function:C', $typeName will be 'C'&lt;/span&gt;&lt;br /&gt;   $typeName = $matches[&lt;span style="color:maroon;"&gt;3&lt;/span&gt;];&lt;br /&gt;   &lt;span style="color:green;"&gt;# e.g. in '$global:host.ui.rawui', child will be 'ui.rawui'&lt;/span&gt;&lt;br /&gt;   $child = $matches[&lt;span style="color:maroon;"&gt;5&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# Scope Variable Name Expansion for $global:, $private:, $script:, $local:&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($Script:ScopeNames -contains $type) {&lt;br /&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($child) {&lt;br /&gt;     &lt;span style="color:green;"&gt;# Handle *multi-level* property and method expansion&lt;/span&gt;&lt;br /&gt;     MultiLevelPropertyExpansion $typeName $child |&lt;br /&gt;     &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {&lt;br /&gt;      $output = $prefix + &lt;span style="color:maroon;"&gt;":"&lt;/span&gt; + $_[&lt;span style="color:maroon;"&gt;"Value"&lt;/span&gt;] + &lt;span style="color:maroon;"&gt;'.'&lt;/span&gt; + $_[&lt;span style="color:maroon;"&gt;"Name"&lt;/span&gt;]&lt;br /&gt;      &lt;span style="color:green;"&gt;# Append "(" for method&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($_[&lt;span style="color:maroon;"&gt;"MemberType"&lt;/span&gt;] -band $Script:Method) { $output += &lt;span style="color:maroon;"&gt;'('&lt;/span&gt;}&lt;br /&gt;      &lt;span style="color:blue;"&gt;return&lt;/span&gt; $output&lt;br /&gt;     }&lt;br /&gt;    } &lt;span style="color:blue;"&gt;else&lt;/span&gt; { &lt;span style="color:green;"&gt;# Expand scope variable name&lt;/span&gt;&lt;br /&gt;     &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; ($scopeVariable &lt;span style="color:blue;"&gt;in&lt;/span&gt;&lt;br /&gt;      (Get-Variable &lt;span style="color:maroon;"&gt;"$($typeName)*"&lt;/span&gt; -Scope $type |&lt;br /&gt;      Sort-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; name)) {&lt;br /&gt;      $prefix + &lt;span style="color:maroon;"&gt;":"&lt;/span&gt; + $scopeVariable.Name&lt;br /&gt;     }&lt;br /&gt;    }&lt;br /&gt;   } &lt;span style="color:blue;"&gt;else&lt;/span&gt; {&lt;br /&gt;    &lt;span style="color:green;"&gt;# Type name expansion for $function:, $variable, $env:, etc&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; ($t &lt;span style="color:blue;"&gt;in&lt;/span&gt;&lt;br /&gt;     (Get-ChildItem ($type + &lt;span style="color:maroon;"&gt;":"&lt;/span&gt; + $typeName + &lt;span style="color:maroon;"&gt;'*'&lt;/span&gt;) |&lt;br /&gt;     Sort-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; name)) {&lt;br /&gt;     $prefix + &lt;span style="color:maroon;"&gt;":"&lt;/span&gt; + $t.Name&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;###&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;### Default functions below this line&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;###&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# Handle property and method expansion...&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'\$(\w+)\.(\w*)'&lt;/span&gt; {&lt;br /&gt;   $variableName = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;]&lt;br /&gt;   $val = Get-Variable -value $variableName&lt;br /&gt;   $pat = $matches[&lt;span style="color:maroon;"&gt;2&lt;/span&gt;] + &lt;span style="color:maroon;"&gt;'*'&lt;/span&gt;&lt;br /&gt;   Get-Member -inputobject $val |&lt;br /&gt;   &lt;span style="color:blue;"&gt;where&lt;/span&gt; { $n = $_.name; `&lt;br /&gt;    $n -like $pat -and $n -notmatch &lt;span style="color:maroon;"&gt;'^([gs]et|op)_'&lt;/span&gt; } |&lt;br /&gt;   &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; {&lt;br /&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($_.MemberType -band $Script:Method) {&lt;br /&gt;     &lt;span style="color:green;"&gt;# Return a method...&lt;/span&gt;&lt;br /&gt;     &lt;span style="color:maroon;"&gt;'$'&lt;/span&gt; + $variableName + &lt;span style="color:maroon;"&gt;'.'&lt;/span&gt; + $_.name + &lt;span style="color:maroon;"&gt;'('&lt;/span&gt;&lt;br /&gt;    } &lt;span style="color:blue;"&gt;else&lt;/span&gt; {&lt;br /&gt;     &lt;span style="color:green;"&gt;# Return a property...&lt;/span&gt;&lt;br /&gt;     &lt;span style="color:maroon;"&gt;'$'&lt;/span&gt; + $variableName + &lt;span style="color:maroon;"&gt;'.'&lt;/span&gt; + $_.name&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# Handle variable name expansion...&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'(.*^\$)(\w+)$'&lt;/span&gt; {&lt;br /&gt;   $prefix = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;]&lt;br /&gt;   $varName = $matches[&lt;span style="color:maroon;"&gt;2&lt;/span&gt;]&lt;br /&gt;   &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; ($v &lt;span style="color:blue;"&gt;in&lt;/span&gt; Get-Childitem (&lt;span style="color:maroon;"&gt;'variable:'&lt;/span&gt; + $varName + &lt;span style="color:maroon;"&gt;'*'&lt;/span&gt;)) {&lt;br /&gt;    $prefix + $v.name&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;# Do completion on parameters (original) ...&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:maroon;"&gt;'^-([\w0-9]*)'&lt;/span&gt; {&lt;br /&gt;   $pat = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;] + &lt;span style="color:maroon;"&gt;'*'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# extract the command name from the string&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# first split the string into statements and pipeline elements&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# This doesnt handle strings however.&lt;/span&gt;&lt;br /&gt;   $cmdlet = [regex]::Split($line, &lt;span style="color:maroon;"&gt;'[|;]'&lt;/span&gt;)[-&lt;span style="color:maroon;"&gt;1&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;#  Extract the trailing unclosed block&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($cmdlet -match &lt;span style="color:maroon;"&gt;'\{([^\{\}]*)$'&lt;/span&gt;) {&lt;br /&gt;    $cmdlet = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;]&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# Extract the longest unclosed parenthetical expression...&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($cmdlet -match &lt;span style="color:maroon;"&gt;'\(([^()]*)$'&lt;/span&gt;) {&lt;br /&gt;    $cmdlet = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;]&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# take the first space separated token of the remaining string&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# as the command to look up. Trim any leading or trailing spaces&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# so you dont get leading empty elements.&lt;/span&gt;&lt;br /&gt;   $cmdlet = $cmdlet.Trim().Split()[&lt;span style="color:maroon;"&gt;0&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# now get the info object for it...&lt;/span&gt;&lt;br /&gt;   $cmdlet = @(Get-Command -type &lt;span style="color:maroon;"&gt;'cmdlet,alias'&lt;/span&gt; $cmdlet)[&lt;span style="color:maroon;"&gt;0&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# loop resolving aliases...&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;while&lt;/span&gt; ($cmdlet.CommandType -eq &lt;span style="color:maroon;"&gt;'alias'&lt;/span&gt;) {&lt;br /&gt;    $cmdlet = @(Get-Command -type &lt;span style="color:maroon;"&gt;'cmdlet,alias'&lt;/span&gt; `&lt;br /&gt;     $cmdlet.Definition)[&lt;span style="color:maroon;"&gt;0&lt;/span&gt;]&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;# expand the parameter sets and emit the matching elements&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; ($n &lt;span style="color:blue;"&gt;in&lt;/span&gt; ($cmdlet.ParameterSets |&lt;br /&gt;    Select-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; -expand parameters)) {&lt;br /&gt;    $n = $n.name&lt;br /&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($n -like $pat) { &lt;span style="color:maroon;"&gt;'-'&lt;/span&gt; + $n }&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;  }&lt;br /&gt; } &lt;span style="color:green;"&gt;# EO switch&lt;/span&gt;&lt;br /&gt;}  &lt;span style="color:green;"&gt;# EO Process&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114982609040723771?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114982609040723771/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114982609040723771' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114982609040723771'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114982609040723771'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/06/extending-tabexpansion-function-part-2.html' title='Extending TabExpansion function Part 2'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114947413626879980</id><published>2006-06-04T21:49:00.000-04:00</published><updated>2006-06-06T22:36:24.303-04:00</updated><title type='text'>Extending TabExpansion function</title><content type='html'>&lt;span style="font-weight: bold;"&gt;EDIT:*&lt;/span&gt; Changed "new" to "New-Object"(Thanks Martin and Mow) in the source on PasteBin.com and jEdit IDE comments, "#{{{", "#}}}" are gone.&lt;br /&gt;Moreover, there is a little bit of change on Mow's tab expansion on PowerShell Tab Completion &lt;a href="http://mow001.blogspot.com/2006/06/powershell-tab-completion-part-2.html"&gt;2&lt;/a&gt;, that when caching for loaded assembly type names occur, progress bars(with help from &lt;a href="http://mow001.blogspot.com/"&gt;/\/\o\/\/&lt;/a&gt; again~) are displayed.  So when you try out &lt;strong&gt;[System.m&lt;/strong&gt;&lt;em&gt;[tab], &lt;/em&gt;you will see two progress bars during caching.  But it actually seems to slow down caching process a bit&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;EDIT2:*&lt;/span&gt; Screenshot: Showing progressbars while caching assembly type names to speed up TabExpansion.&lt;br /&gt;The following happens the first time and the first time only(well that is until you actually delete $global:dtAssemblies) during first Type Name expansion &lt;span style="font-weight: bold;"&gt;[Sys&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;a href="http://img.photobucket.com/albums/v138/dance2die/blogger/TabExpansionCaching.gif" target="_blank"&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/blogger/TabExpansionCaching-smaller.gif" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;EDIT3:*&lt;/span&gt; Modified TabExpansion &lt;a href="http://powershell.pastebin.com/764311"&gt;http://powershell.pastebin.com/764311&lt;/a&gt;.&lt;br /&gt;Thanks, justin for pointing out the regex problem~&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Inspired by &lt;a href="http://mow001.blogspot.com/"&gt;/\/\o\/\/&lt;/a&gt;'s PowerShell Tab Completion &lt;a href="http://mow001.blogspot.com/2006/05/powershell-tab-completion.html"&gt;1&lt;/a&gt; &amp; &lt;a href="http://mow001.blogspot.com/2006/06/powershell-tab-completion-part-2.html"&gt;2&lt;/a&gt; and was playing around with him on &lt;a href="irc://irc.freenode.net/powershell"&gt;#powershell&lt;/a&gt; on FreeNode, I just decided to expand the tabExpansion function a bit more(with tips from Mow on IRC chatroom for Sorting and expanding partial variable names).&lt;br /&gt;&lt;br /&gt;In the second part of Mow's &lt;a href="http://mow001.blogspot.com/2006/06/powershell-tab-completion-part-2.html"&gt;PowerShell Tab Completion Part 2&lt;/a&gt;, Mow has saved cached assembly type names in &lt;span style="font-style: italic;"&gt;$global:dtAssemblies&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Default tabExpansion function does not handle variable names with scope identifier appeneded. So the following will not work&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;$global:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$local:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$script:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$private:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;/blockquote&gt;So why not just extend tabExpansion function.&lt;br /&gt;While at it, let's support "$variable:", "$env:" and "$function:" as well since they have the same variable name matching patterns.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:maroon;"&gt;'(.*^\$)(\w+):(\w*)$'&lt;/span&gt; {&lt;br /&gt;$type = $matches[&lt;span style="color:maroon;"&gt;2&lt;/span&gt;];          &lt;span style="color:green;"&gt;# function, variable, etc.. that are not scopes&lt;/span&gt;&lt;br /&gt;$prefix = $matches[&lt;span style="color:maroon;"&gt;1&lt;/span&gt;] + $type;  &lt;span style="color:green;"&gt;# $ + function&lt;/span&gt;&lt;br /&gt;$typeName = $matches[&lt;span style="color:maroon;"&gt;3&lt;/span&gt;];        &lt;span style="color:green;"&gt;# e.g. in '$function:C', value will be 'C'&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;   if&lt;/span&gt; ($_ScopeNames -contains $type) {&lt;br /&gt;&lt;span style="color:green;"&gt;      # Scope Variable Name Expansion&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt; foreach&lt;/span&gt; ($scopeVariable &lt;span style="color:blue;"&gt;in&lt;/span&gt;&lt;br /&gt; (Get-Variable &lt;span style="color:maroon;"&gt;"$($typeName)*"&lt;/span&gt; -Scope $type  Sort-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; name)) {&lt;br /&gt; $prefix + &lt;span style="color:maroon;"&gt;":"&lt;/span&gt; + $scopeVariable.Name&lt;br /&gt;}&lt;br /&gt;} &lt;span style="color:blue;"&gt;else&lt;/span&gt; {&lt;br /&gt;&lt;span style="color:green;"&gt;# Type name expansion($function:, $variable, $env: ,etc)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;      foreach&lt;/span&gt; ($t &lt;span style="color:blue;"&gt;in&lt;/span&gt; (Get-ChildItem ($type + &lt;span style="color:maroon;"&gt;":"&lt;/span&gt; + $typeName + &lt;span style="color:maroon;"&gt;'*'&lt;/span&gt;)  Sort-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; name)) {&lt;br /&gt; $prefix + &lt;span style="color:maroon;"&gt;":"&lt;/span&gt; + $t.Name&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:blue;"&gt;   break&lt;/span&gt;;&lt;br /&gt;}&lt;/pre&gt;I am not sure what to call "$function:", "$variable:" and "$env:" so I just called them as "Type".&lt;br /&gt;In the above code snippet, '(.*^\$)(\w+):(\w*) matches "$function:", "$env:" or anything like "$" + "foo" + ":" and variable names with scope name appended are expanded differently from the ones with types.(&lt;- well how should i be expressing this in clearer terms...) Scope names are checked with &lt;span style="font-style: italic;color:blue;" &gt;if&lt;/span&gt;&lt;span style="font-style: italic;"&gt; ($_ScopeNames -contains $type) &lt;/span&gt;and "$_ScopeNames" is an array containing "global", "local", "script" and "private" and "$_ScopeNames" is declared in "begin{}" block of TabExpansion function like the following (All Regular Expression checks are processed inside "process{}" block.)&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;begin {&lt;br /&gt;$_Method = [Management.Automation.PSMemberTypes] &lt;span style="color:maroon;"&gt;'Method,CodeMethod,ScriptMethod,ParameterizedProperty'&lt;/span&gt;&lt;br /&gt;$_ScopeNames = @(&lt;span style="color:maroon;"&gt;"global"&lt;/span&gt;, &lt;span style="color:maroon;"&gt;"local"&lt;/span&gt;, &lt;span style="color:maroon;"&gt;"script"&lt;/span&gt;, &lt;span style="color:maroon;"&gt;"private"&lt;/span&gt;)&lt;br /&gt;}&lt;/pre&gt;Now, not only the following works,&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;$global:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$local:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$script:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$private:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;/blockquote&gt;But also, you can expand variable names for&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;$env:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$function:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;$variable:&lt;/span&gt;&lt;span style="font-style: italic;"&gt;[tab]&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;A simple extension to TabExpansion makes life on Console much less painful... ;)&lt;br /&gt;You can find the full source of my TabExpansion function, which includes sources posted on Mow's blogs "PowerShell Tab Completion &lt;a href="http://mow001.blogspot.com/2006/05/powershell-tab-completion.html"&gt;1&lt;/a&gt; &amp;amp; &lt;a href="http://mow001.blogspot.com/2006/06/powershell-tab-completion-part-2.html"&gt;2&lt;/a&gt;", on &lt;a href="http://powershell.pastebin.com/764311"&gt;powershell.pastebin.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114947413626879980?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114947413626879980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114947413626879980' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114947413626879980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114947413626879980'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/06/extending-tabexpansion-function.html' title='Extending TabExpansion function'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114892102770012831</id><published>2006-05-29T12:34:00.000-04:00</published><updated>2006-05-29T12:46:17.833-04:00</updated><title type='text'>PowerShell Del.icio.us bookmarks</title><content type='html'>I was fed up with all the favoriates I have about PowerShell links and decided to put'em all on my &lt;a href="http://favorites.live.com/"&gt;Windows Live Favoriates site&lt;/a&gt; but I had some difficulties managing/adding contents to the site.&lt;br /&gt;&lt;br /&gt;I just decided to go for &lt;a href="http://del.icio.us"&gt;del.icio.us&lt;/a&gt; and started adding PowerShell bookmarks yesterday (05/28/2006) on &lt;a href="http://del.icio.us/powershell"&gt;http://del.icio.us/powershell&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;There is a &lt;a href="http://www.spreadfirefox.com"&gt;FireFox&lt;/a&gt; &lt;a href="https://addons.mozilla.org/firefox/1532/"&gt;extension&lt;/a&gt; for Delicious so I installed it and it was a breeze to add bookmarks.&lt;br /&gt;Anyways, I wish people could leave comments on what kind of categories/tags I should and should not include on &lt;a href="http://del.icio.us"&gt;delicious&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://del.icio.us/powershell"&gt;http://del.icio.us/powershell&lt;/a&gt; certainly is not well tagged in my opinion since I just was adding without much thoughts initially...&lt;br /&gt;&lt;br /&gt;Oh yeah, I would also appreciate if someone can provide me more links to PowerShell related posts or sites.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt; &lt;a href="http://technorati.com/tag/Delicious" rel="tag"&gt;Delicious&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114892102770012831?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114892102770012831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114892102770012831' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114892102770012831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114892102770012831'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/05/powershell-delicious-bookmarks.html' title='PowerShell Del.icio.us bookmarks'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114692019278439842</id><published>2006-05-06T08:54:00.000-04:00</published><updated>2006-05-06T09:06:41.863-04:00</updated><title type='text'>PowerShell RC1 Updates</title><content type='html'>Because of some issues discovered, PowerShell team has released an updated version of PowerShell RC1.&lt;br /&gt;&lt;br /&gt;The links to download sites can be found on the &lt;a href="http://blogs.msdn.com/powershell/archive/2006/05/06/591220.aspx"&gt;Windows PowerShell blog&lt;/a&gt; home page&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114692019278439842?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114692019278439842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114692019278439842' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114692019278439842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114692019278439842'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/05/powershell-rc1-updates.html' title='PowerShell RC1 Updates'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114619206255708917</id><published>2006-04-27T21:49:00.000-04:00</published><updated>2006-04-27T22:41:02.573-04:00</updated><title type='text'>Option Explicit, I mean "Strict" switch...</title><content type='html'>I have been waiting for this feature for quite a while.&lt;br /&gt;Setting Visual Basic's "Option Explict" statement like switch in PowerShell.&lt;br /&gt;&lt;br /&gt;The Magic Word is..&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Set-PSDebug -Strict&lt;/span&gt;&lt;br /&gt;Upon executing the command, according to help page(Get-Help Set-PSDebug),&lt;br /&gt;&lt;blockquote&gt;the interpreter will throw an exception if the referenced variable hasn’t been set yet.&lt;br /&gt;&lt;/blockquote&gt;Let's see when that feature might come in handy.&lt;br /&gt;&lt;blockquote&gt;PS&gt; Set-PSDebug -Off&lt;br /&gt;PS&gt; function add($x, $y) { $x + $z }&lt;br /&gt;PS&gt; add 1 10&lt;br /&gt;1&lt;br /&gt;PS&gt; $z = 100&lt;br /&gt;PS&gt; add 1 10&lt;br /&gt;101&lt;br /&gt;&lt;/blockquote&gt;As you can see, with "Strict" mode off(well "Strict" flag is of type Switch, and all the Boolean flags were replaced with Switches), the PowerShell interpreter simple accepts the fact that function "add" just adds value of $x and $z without caring about what the value of $z is.&lt;br /&gt;&lt;br /&gt;Now, let's set the "Strict" option on&lt;br /&gt;&lt;blockquote&gt;PS&gt; Set-PSDebug -Strict&lt;br /&gt;PS&gt; ri function:add; rv z # remove "add" function and the variable $z&lt;br /&gt;PS&gt; function add($x, $y) { $x + $z }&lt;br /&gt;PS&gt; add 1 10&lt;br /&gt;The variable $z cannot be retrieved because it has not been set yet.&lt;br /&gt;At line:1 char:31&lt;br /&gt;+ function add($x, $y) { $x + $z  &lt;&lt;&lt;&lt; }&lt;br /&gt;&lt;/blockquote&gt;Although the demo is really too simple of a case, in your scripts, you might have variables that you are not keeping track of but being still used somewhere in your scripts.&lt;br /&gt;&lt;br /&gt;Well, if you are using PowerShell just for interactive uses for a quick and dirty operations, forget about this feature but then if you are writing cmdlets, setting this option always would be a good idea. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114619206255708917?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114619206255708917/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114619206255708917' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114619206255708917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114619206255708917'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/04/option-explicit-i-mean-strict-switch.html' title='Option Explicit, I mean &quot;Strict&quot; switch...'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114393444570069010</id><published>2006-04-01T17:37:00.000-05:00</published><updated>2006-04-01T18:40:38.883-05:00</updated><title type='text'>[MSH] Extending System.Security.SecureString</title><content type='html'>I was reading &lt;a href="http://blogs.msdn.com/monad"&gt;Monad Technology Blog&lt;/a&gt; about &lt;a href="http://blogs.msdn.com/monad/archive/2006/03/27/562100.aspx"&gt;Base64 Encode/Decode a string&lt;/a&gt;, which deals with extending a .NET object &lt;a href="http://msdn2.microsoft.com/en-us/library/system.string.aspx"&gt;System.String&lt;/a&gt; to include script properties (which you can also add in an interactive mode through "add-member -type ScriptProperty" but lasts only during the given session) called "ToBase64String" and "FromBase64String".&lt;br /&gt;&lt;br /&gt;Well, to apply the concept, I have decided to extend &lt;a href="http://msdn2.microsoft.com/en-us/library/system.security.securestring.aspx"&gt;System.Security.SecureString&lt;/a&gt; by creating a new Monad XML type file called "my.types.mshxml"(the name is from Monad Technology blog) at $MshHome(for most of people, it should be "C:\Program Files\Microsoft Command Shell\v1.0") and then extended SecureString to include a script property called &lt;span style="font-style: italic;"&gt;UnsecureString&lt;/span&gt;.&lt;br /&gt;&lt;span style="font-style: italic;"&gt;UnsecureString&lt;/span&gt; decodes SecureString's content.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;*NOTE&lt;/span&gt;: I won't go into details on how you can view SecureString content.  If you would like to know how you can view a secure string content and want to find out more about Windows Data Proctection, please refer to following sites&lt;br /&gt;&lt;ul&gt;&lt;li&gt;/\/\o\/\/'s blog: &lt;a href="http://mow001.blogspot.com/2005/11/get-credential-and-decrypting.html"&gt;Get-credential and Decrypting a SecureString in MSH&lt;/a&gt;&lt;/li&gt;&lt;li&gt;MSDN: &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsecure/html/windataprotection-dpapi.asp"&gt;Windows Data Protection&lt;/a&gt;(or follow the link on Mow's blog)&lt;/li&gt;&lt;/ul&gt;&lt;blockquote&gt;&lt;strong&gt;My.Types.Mshxml&lt;/strong&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style=' color: Blue;'&gt;&amp;lt;?&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;xml&lt;/span&gt; &lt;span style=' color: Red;'&gt;version&lt;/span&gt;="&lt;span style=' color: Blue;'&gt;1.0&lt;/span&gt;" &lt;span style=' color: Red;'&gt;encoding&lt;/span&gt;="&lt;span style=' color: Blue;'&gt;utf-8&lt;/span&gt;" &lt;span style=' color: Blue;'&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;Types&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;Type&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;Name&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;System.Security.SecureString&lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;/&lt;span style=' color: Maroon;'&gt;Name&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;Members&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;ScriptProperty&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;Name&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;UnsecureString&lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;/&lt;span style=' color: Maroon;'&gt;Name&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;GetScriptBlock&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                    [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($this))&lt;br /&gt;                &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;/&lt;span style=' color: Maroon;'&gt;GetScriptBlock&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;/&lt;span style=' color: Maroon;'&gt;ScriptProperty&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;/&lt;span style=' color: Maroon;'&gt;Members&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;/&lt;span style=' color: Maroon;'&gt;Type&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style=' color: Blue;'&gt;&amp;lt;&lt;/span&gt;/&lt;span style=' color: Maroon;'&gt;Types&lt;/span&gt;&lt;span style=' color: Blue;'&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt;Then, as you see in Monad Technology Blog, load the newly created custom type data:&lt;br /&gt;&lt;strong&gt;Update-TypeData $MshHome\My.Types.Mshxml&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Let's see if &lt;a href="http://msdn2.microsoft.com/en-us/library/system.security.securestring.aspx"&gt;System.Security.SecureString&lt;/a&gt; has been extended or not&lt;blockquote&gt;&lt;pre&gt;MSH&gt;$admin = get-credential administrator&lt;br /&gt;MSH&gt;($admin.password).getType().fullName&lt;br /&gt;System.Security.SecureString&lt;br /&gt;MSH&gt;$admin.password | get-member -MemberType ScriptProperty | format-list&lt;br /&gt;&lt;br /&gt;TypeName   : System.Security.SecureString&lt;br /&gt;Name       : UnsecureString&lt;br /&gt;MemberType : ScriptProperty&lt;br /&gt;Definition : System.Object UnsecureString {get=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($this));}&lt;/pre&gt;&lt;/blockquote&gt;Now, you can see that SecureString type has been extended with "UnsecureString".&lt;br /&gt;From this point on,&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;MSH&gt;$admin.password&lt;br /&gt;System.Security.SecureString&lt;br /&gt;MSH&gt;$admin.password.UnsecureString&lt;br /&gt;*** secret ***&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;where &lt;span style="font-style: italic;"&gt;*** secret ***&lt;/span&gt; is your decoded password string.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But this raises a couple of questions.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Displaying clear, unsecure string for the credential object is a security threat&lt;/li&gt;&lt;li&gt;I can't answer "IMPORTANT" note posted on &lt;a href="%3Ca%20href=%22http://blogs.msdn.com/monad/archive/2006/03/27/562100.aspx%22%3E"&gt;Monad Technolog Blog&lt;/a&gt; site&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&amp;lt;IMPORTANT POINT&amp;gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;strong&gt;Whenever you are adding some functions, you should make a conscious decision about whether those functions are best exposed as a "function" or as a "type extension".&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&amp;lt;/IMPORTANT POINT&amp;gt;&lt;br /&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt;I don't know when extending SecureString would come in handy without causing any security problems.&lt;br /&gt;Will anyone be able to justify the need for extending SecureString to display clear string?&lt;br /&gt;Well it's all up to you whether you would want to or not. (I just like to mess around...)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114393444570069010?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114393444570069010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114393444570069010' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114393444570069010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114393444570069010'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/04/msh-extending-systemsecuritysecurestri.html' title='[MSH] Extending System.Security.SecureString'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114340394645462356</id><published>2006-03-26T14:21:00.000-05:00</published><updated>2006-03-26T15:12:54.363-05:00</updated><title type='text'>[MSH] How to change a Process's Priority</title><content type='html'>There are a lot of posts about how to get processes' name and priorities but I haven't been able to find ways to change a process's priority easily.&lt;br /&gt;&lt;br /&gt;Suppose that you are (un)zipping a large file and would like to change the priority of the operation set to "High" to finish the task quickly.  One can simply just fire up a Task Manager and set the priority of the process manually with mouse clicks.&lt;br /&gt;&lt;br /&gt;But why do so when there is a way to do it with few keystrokes...&lt;br /&gt;&lt;br /&gt;If you want to change the process of zip operation you can simply do something like&lt;br /&gt;&lt;blockquote&gt;#RealTime is generally not recommended...(NOTE: One-liner)&lt;br /&gt;gps -p zip.exe | foreach { $_.PriorityClass = "RealTime" }&lt;/blockquote&gt;&lt;br /&gt;where valid values for "PriorityClass" can be retrieved through the following function&lt;br /&gt;&lt;blockquote&gt;MSH&gt;[Enum]::getNames("Diagnostics.ProcessPriorityClass")&lt;br /&gt;Normal&lt;br /&gt;Idle&lt;br /&gt;High&lt;br /&gt;RealTime&lt;br /&gt;BelowNormal&lt;br /&gt;AboveNormal&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;But the problem with using "foreach" statement in the next pipe is that, when pipe more than one process into the foreach statement, all of them will have their priority set to "RealTime".  I don't like the following solution but just to be on the safe side, you can do the following&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;# Apply the process priority only to the first input object(NOTE: One-liner)&lt;br /&gt;gps -processname "process_name" | &amp;{ $input.moveNext(); $input.Current.PriorityClass = "RealTime" }&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Basically you are setting the priority of the first passed pipe object(represented by $input)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You might as well create a function to change the priority more easily&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; set-ProcessPriority { &lt;br /&gt;    param($processName = $(throw &lt;SPAN style="COLOR: maroon"&gt;"Enter process name"&lt;/SPAN&gt;), $priority = &lt;SPAN style="COLOR: maroon"&gt;"Normal"&lt;/SPAN&gt;)&lt;br /&gt;&lt;br /&gt;    get-process -processname $processname | &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; { $_.PriorityClass = $priority }&lt;br /&gt;    write-host &lt;SPAN style="COLOR: maroon"&gt;"`"$($processName)`"'s priority is set to `"$($priority)`""&lt;/SPAN&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# When zip is running&lt;br /&gt;MSH&gt; set-ProcessPriority zip "High"&lt;br /&gt;"zip"'s priority is set to "High"&lt;br /&gt;&lt;br /&gt;# When zip operation is over,("Normal" is the default priority level)&lt;br /&gt;MSH set-ProcessPriority zip&lt;br /&gt;"zip"'s priority is set to "Normal"&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;To actually see what the priory level is the for given process just to make sure&lt;br /&gt;&lt;blockquote&gt;MSH&gt; gps zip | select name,priorityclass  | ft -auto&lt;br /&gt;&lt;br /&gt;Name PriorityClass&lt;br /&gt;---- -------------&lt;br /&gt;zip         Normal&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;By the way, I am sure that there could be easier ways to change process priorities.  I would love it if anyone can suggest other ways...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114340394645462356?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114340394645462356/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114340394645462356' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114340394645462356'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114340394645462356'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/03/msh-how-to-change-processs-priority.html' title='[MSH] How to change a Process&apos;s Priority'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114219653657396892</id><published>2006-03-12T15:36:00.000-05:00</published><updated>2006-03-12T15:49:23.226-05:00</updated><title type='text'>[MSH] display and extract zip contents</title><content type='html'>In the previous post, I have talked about how to display zip contents of a file.&lt;br /&gt;I have realized that ,while writing extraction script(out-ZipContent), it'd be better to convert the script into a snapin than using a simple script to support variety of features(such as extracting zip file contents into different folders) as well as using different Zip libraries(moreover, it's hard for me to use library functions Monadishly...)&lt;br /&gt; So I will try to convert these scripts into Cmdlets later on and post the source on somewhere on GotDotNet...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For now, I have separated retrieving ZipStream object into another function called "Get-ZipStream", displaying logic into "Get-ZipContent" and extracting contents into "Out-ZipContent".&lt;br /&gt;&lt;br /&gt;Well, I don't want to go too deep into usages and stuff but here is how cmdlets can be used.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;To Display zip contents&lt;/strong&gt;&lt;blockquote&gt;MSH&gt;get-zipstream .\zipFile.zip | get-zipContent&lt;/blockquote&gt;&lt;br /&gt;&lt;strong&gt;To Extract zip contents&lt;/strong&gt;&lt;blockquote&gt;MSH&gt;get-zipstream .\zipFile.zip | out-zipContent&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Get-ZipStream: Returns ZipStream&lt;/strong&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; Get-ZipStream {&lt;br /&gt; param($zipFileName = $(throw &lt;SPAN style="COLOR: maroon"&gt;"Enter Zip File Name"&lt;/SPAN&gt;))&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# Load J# library&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# used "out-null" instead of "[void]" since "out-null" would not display&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# loaded assembly even if there was an exception thrown&lt;/SPAN&gt;&lt;br /&gt; [System.Reflection.Assembly]::LoadWithPartialName(&lt;SPAN style="COLOR: maroon"&gt;"vjslib"&lt;/SPAN&gt;) | out-&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# 1) Open "java.io.FileInputStream" for a zip file&lt;/SPAN&gt;&lt;br /&gt; $fis = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; java.io.FileInputStream($zipFileName)&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# 2) Pipe File Input stream object to "java.io.ZipInputStream"&lt;/SPAN&gt;&lt;br /&gt; $zis = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; java.util.zip.ZipInputStream($fis)&lt;br /&gt;&lt;br /&gt; trap {&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($zis -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) { $zis.close() }&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($fis -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) { $fis.close() }&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;break&lt;/SPAN&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# Return the zip stream&lt;/SPAN&gt;&lt;br /&gt; $zis&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Get-ZipContent: Displays Zip contents&lt;/strong&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; Get-ZipContent {&lt;br /&gt; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($args[&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;] -eq $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) {&lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# Retrive only the first value&lt;/SPAN&gt;&lt;br /&gt;  $input.moveNext() | out-&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&lt;br /&gt;  $zipStream = $input.get_Current()&lt;br /&gt; } &lt;br /&gt; &lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# Load J# library&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# used "out-null" instead of "[void]" since "out-null" would not display&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# loaded assembly even if there was an exception thrown&lt;/SPAN&gt;&lt;br /&gt; [System.Reflection.Assembly]::LoadWithPartialName(&lt;SPAN style="COLOR: maroon"&gt;"vjslib"&lt;/SPAN&gt;) | out-&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&lt;br /&gt; &lt;br /&gt; trap { &lt;SPAN style="COLOR: blue"&gt;break&lt;/SPAN&gt;; }&lt;br /&gt; &lt;br /&gt; &lt;SPAN style="COLOR: blue"&gt;while&lt;/SPAN&gt; (($ze = $zipStream.getNextEntry()) -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) {&lt;br /&gt;  $ze.toString()&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# Close "ZipInputStream" first and then "FileInputStream"&lt;/SPAN&gt;&lt;br /&gt; $zipStream.close()&lt;br /&gt; remove-variable zipStream&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Out-ZipContent: Extracts zip file content&lt;/strong&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; Out-ZipContent {&lt;br /&gt; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($args[&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;] -eq $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) {&lt;br /&gt;  $input.MoveNext()&lt;br /&gt;  $zis = $input.get_Current()&lt;br /&gt; } &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt; {&lt;br /&gt;  $zis = $args[&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;]&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; trap { &lt;SPAN style="COLOR: blue"&gt;break&lt;/SPAN&gt;; }&lt;br /&gt;&lt;br /&gt; [System.Reflection.Assembly]::LoadWithPartialName(&lt;SPAN style="COLOR: maroon"&gt;"vjslib"&lt;/SPAN&gt;) | out-&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: blue"&gt;while&lt;/SPAN&gt; (($ze = $zis.getNextEntry()) -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) {&lt;br /&gt;  $fn = $ze.getName()&lt;br /&gt;  $idx = $fn.LastIndexOf(&lt;SPAN style="COLOR: maroon"&gt;"/"&lt;/SPAN&gt;)&lt;br /&gt;  Write-Host &lt;SPAN style="COLOR: maroon"&gt;"`$fn = $($fn)"&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# we need create a directory&lt;/SPAN&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($idx -gt &lt;SPAN style="COLOR: maroon"&gt;1&lt;/SPAN&gt;) {&lt;br /&gt;   $dir = $fn.SubString(&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, $idx)&lt;br /&gt;   $dir = &lt;SPAN style="COLOR: maroon"&gt;"$((pwd).path)\$($dir)"&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt;   &lt;SPAN style="COLOR: green"&gt;# Since the directory doesn't exist, we now create it&lt;/SPAN&gt;&lt;br /&gt;   &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ( !(test-path $dir -type container) ) {&lt;br /&gt;    new-item -path $dir -type directory&lt;br /&gt;    Write-host &lt;SPAN style="COLOR: maroon"&gt;"Created $($dir)"&lt;/SPAN&gt;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  $file = &lt;SPAN style="COLOR: maroon"&gt;"$((pwd).path)\$($fn)"&lt;/SPAN&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# Write only for leaf files&lt;/SPAN&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ( !(test-path  $file -type container) ) {&lt;br /&gt;   [&lt;SPAN style="COLOR: blue"&gt;sbyte&lt;/SPAN&gt;[]]$buf = [&lt;SPAN style="COLOR: blue"&gt;sbyte&lt;/SPAN&gt;[]](@(&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;.&lt;SPAN style="COLOR: maroon"&gt;.127&lt;/SPAN&gt;) * &lt;SPAN style="COLOR: maroon"&gt;8&lt;/SPAN&gt;)&lt;br /&gt;   $fos = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; Java.io.fileOutputStream($file)&lt;br /&gt;&lt;br /&gt;   &lt;SPAN style="COLOR: blue"&gt;while&lt;/SPAN&gt; ( ($len = $zis.read($buf)) -ge &lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt; ) {&lt;br /&gt;    $fos.Write($buf, &lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, $len)&lt;br /&gt;   }; $fos.close()&lt;br /&gt;   Write-Host &lt;SPAN style="COLOR: maroon"&gt;"Extracted $($file)"&lt;/SPAN&gt;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114219653657396892?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114219653657396892/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114219653657396892' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114219653657396892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114219653657396892'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/03/msh-display-and-extract-zip-contents.html' title='[MSH] display and extract zip contents'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114107773595764856</id><published>2006-02-27T16:42:00.000-05:00</published><updated>2006-02-27T17:25:00.986-05:00</updated><title type='text'>[MSH] Displaying Zip File contents</title><content type='html'>Let's have some fun with zip files.&lt;br /&gt;&lt;br /&gt;I have searched through MSDN document on whether .NET library but could not finddd&lt;br /&gt;any C#/VB.net library that deals with Zip file content.&lt;br /&gt;&lt;br /&gt;I have been googling around the web but found a useful J# library for dealing with&lt;br /&gt;zip files easily.  The name of J# library is called "VJSLIB.DLL".&lt;br /&gt;&lt;br /&gt;Here is the step on how to get a Zip file content&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Open "java.io.FileInputStream" for a zip file&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Pipe File Input stream object to "java.io.ZipInputStream"&lt;/li&gt;&lt;br /&gt;&lt;li&gt;While there exists a content in a zip input stream, get a content of type "ZipEntry"&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Close "ZipInputStream" first and then "FileInputStream"&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: green"&gt;# Author: DBMwS&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;# Date: 02/27/2006 @ 04:13 PM EST&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;# Description: Retrieve a Zip file's content&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;#  (either display only files inside the zip file or return ZipEntry object)&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;# Note: This function requires J# Library, "vjslib"&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;# Usage: get-ZipContent file_name [[System.Bool] -toString]&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;# Reference: http://codeproject.com/csharp/VmEasyZipUnZip.asp&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;# Params&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;#  1) $zipFileName: Path of zip file&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: green"&gt;# 2) $toString: return name of zip content, otherwise return ZipEntry&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; Get-ZipContent {&lt;br /&gt; param($zipFileName = $(throw &lt;SPAN style="COLOR: maroon"&gt;"Enter Zip File Name"&lt;/SPAN&gt;), [&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;]$toString = $&lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;)&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# Load J# library&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# used "out-null" instead of "[void]" since "out-null" would not display&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# loaded assembly even if there was an exception thrown&lt;/SPAN&gt;&lt;br /&gt; [System.Reflection.Assembly]::LoadWithPartialName(&lt;SPAN style="COLOR: maroon"&gt;"vjslib"&lt;/SPAN&gt;) | out-&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# 1) Open "java.io.FileInputStream" for a zip file&lt;/SPAN&gt;&lt;br /&gt; $fis = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; java.io.FileInputStream($zipFileName)&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# 2) Pipe File Input stream object to "java.io.ZipInputStream"&lt;/SPAN&gt;&lt;br /&gt; $zis = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; java.util.zip.ZipInputStream($fis)&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# 3) While there exists a content in a zip input stream, get a content of type "ZipEntry"&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: blue"&gt;while&lt;/SPAN&gt; (($ze = $zis.getNextEntry()) -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) {&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($toString) {&lt;br /&gt;   &lt;SPAN style="COLOR: green"&gt;# Pass string value to pipe&lt;/SPAN&gt;&lt;br /&gt;   Write-&lt;SPAN style="COLOR: blue"&gt;Object&lt;/SPAN&gt; $ze.ToString()&lt;br /&gt;  } &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt; {&lt;br /&gt;   &lt;SPAN style="COLOR: green"&gt;# Pass actualy ZipEntry object to pipe&lt;/SPAN&gt;&lt;br /&gt;   $ze&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# 4) Close "ZipInputStream" first and then "FileInputStream"&lt;/SPAN&gt;&lt;br /&gt; $zis.close()&lt;br /&gt; $fis.close()&lt;br /&gt;&lt;br /&gt; trap {&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($zis -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) { $zis.close() }&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($fis -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) { $fis.close() }&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;break&lt;/SPAN&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;/PRE&gt;It is still not complete since, it does not list a zip file inside a given zip file name(no recursive listing)&lt;br /&gt;But I have left that part out on purpose since "get-ZipContent" can be called recursively in a while loop in another function.&lt;br /&gt;&lt;br /&gt;Here is how one can utilize "Get-ZipContent"&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;MSH&gt;ls | where {!$_.MshIsContainer -and $_.name -like "*.zip"} | foreach { get-zipcontent $_.fullname } | where { $_ -like "*.jpg" }&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;In above code snippet, i have used "where {!$_.MshIsContainer -and $_.name -like "*.zip"}" to filter out directories and select files with only "*.zip" extension&lt;br /&gt;(Well, if you don't filter out files that way, get-ZipContent would fail half way when a directory or a non-zip file has been passed to it)&lt;br /&gt;&lt;br /&gt;Well, I will be talking about how to actually "extract" the contents in the next blog.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; Tested under both Monad v3.0 &amp; v3.1 ;) Refer to /\/\o\/\/'s blog on Beta v3.1 release &lt;a href="http://mow001.blogspot.com/2006/02/windows-monad-shell-msh-beta-31_27.html"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reference:&lt;/strong&gt; &lt;a href="http://codeproject.com/csharp/VmEasyZipUnZip.asp"&gt;Zip and Unzip from a C# program using J# runtime by Valeri&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114107773595764856?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114107773595764856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114107773595764856' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114107773595764856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114107773595764856'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/02/msh-displaying-zip-file-contents.html' title='[MSH] Displaying Zip File contents'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114090529875102519</id><published>2006-02-25T17:02:00.000-05:00</published><updated>2006-02-25T17:30:16.066-05:00</updated><title type='text'>[MSH] MSH Analyzer</title><content type='html'>Well, Karl Prosser has create his own GUI Msh hosting environment.&lt;br /&gt;I think it's still in pre-alpha status(well Karl calls it a "Proof of Concept" stage)&lt;br /&gt;&lt;br /&gt;It supports both one-line and multi-line command support and automatically dumps returned objects' class information.  In the current screenshot on his &lt;a href="http://www.karlprosser.com/coder/?p=13"&gt;site&lt;/a&gt;, you don't see "XML" table, but if you do something like&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$xml = [xml]"&amp;lt;xml&amp;gt;&amp;lt;title&amp;gt;some title&amp;lt;/title&amp;gt;&amp;lt;name&amp;gt;some name&amp;lt;/name&amp;gt;&amp;lt;/xml&amp;gt;"&lt;br /&gt;$xml&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;You can see parsed xml data as you see in Internet explorer.&lt;br /&gt;Well, just try it out yourself.&lt;br /&gt;&lt;br /&gt;Go download the executable file &lt;a href="http://www.karlprosser.com/coder/?p=13"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114090529875102519?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114090529875102519/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114090529875102519' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114090529875102519'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114090529875102519'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/02/msh-msh-analyzer.html' title='[MSH] MSH Analyzer'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114067362994754644</id><published>2006-02-22T23:43:00.000-05:00</published><updated>2006-02-23T12:31:34.636-05:00</updated><title type='text'>[MSH] How to a[void] returning multiple values from a function</title><content type='html'>I have succesfully made one of C# application I was working on at work to call MSH script on the fly during runtime.  Everything seemed to have been working fine until I have encounted this problem that &lt;span style="font-weight:bold;"&gt;MSH functions can return mutiple values&lt;/span&gt;  I have passed a variable named &lt;span style="font-style:italic;"&gt;$arr&lt;/span&gt; of type &lt;a href="http://msdn2.microsoft.com/en-us/library/system.collections.arraylist.aspx"&gt;System.Collections.ArrayList&lt;/a&gt; to the Msh Script through&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;Runspace rs = RunspaceFactory.CreateRunspace();&lt;br /&gt;rs.SessionStateProxy.SetVariable(&lt;span style=' color: Maroon;'&gt;"arr"&lt;/span&gt;, &lt;span style=' color: Blue;'&gt;new&lt;/span&gt; ArrayList());&lt;br /&gt;&lt;span style=' color: Green;'&gt;/*** snip ***/&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;string&lt;/span&gt; cmd = &lt;span style=' color: Maroon;'&gt;". .\\parse-file.msh"&lt;/span&gt;;&lt;br /&gt;Pipeline pl = rs.CreatePipeline(cmd);&lt;/pre&gt;&lt;/blockquote&gt;From here on, a variable named &lt;span style="font-style:italic;"&gt;$arr&lt;/span&gt; is visible in "parse-file.msh".&lt;br /&gt;&lt;br /&gt;Now in "parse-file.msh" script, I tried something like(&lt;strong&gt;NOTE&lt;/strong&gt;: In actual "parse-file.msh", there is no initialization code for $arr to ArrayList, in the following function, $arr are initialized as a demonstrative purpose only, /\/\o\/\/, I have cleared it up here :))&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;MSH&amp;gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; bar {&lt;br /&gt;&amp;gt;&amp;gt; $arr = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Collections.ArrayList&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;)&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;)&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;)&lt;br /&gt;&amp;gt;&amp;gt; &lt;br /&gt;&amp;gt;&amp;gt; &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; $arr&lt;br /&gt;&amp;gt;&amp;gt; }&lt;br /&gt;&amp;gt;&amp;gt; &lt;br /&gt;MSH&amp;gt;bar&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;And the function returns 4 values, 3 int32 values and 1 3-element ArrayList object, instead of just the contents of &lt;span style="font-style:italic;"&gt;$arr&lt;/span&gt;.&lt;br /&gt;We can confirm that through the following snippet&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;PRE&gt;MSH&amp;gt;&lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; multiple-returns {&lt;br /&gt;&amp;gt;&amp;gt; $arr = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; System.Collections.ArrayList&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;SPAN style="COLOR: maroon"&gt;5&lt;/SPAN&gt;)&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;SPAN style="COLOR: maroon"&gt;6&lt;/SPAN&gt;)&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;SPAN style="COLOR: maroon"&gt;7&lt;/SPAN&gt;)&lt;br /&gt;&amp;gt;&amp;gt; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; $arr}&lt;br /&gt;&amp;gt;&amp;gt; &lt;br /&gt;MSH&amp;gt;multiple-returns&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;1&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;2&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;5&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;6&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;7&lt;/SPAN&gt;&lt;br /&gt;MSH&amp;gt;$a, $b, $c, $d, $e = multiple-returns&lt;br /&gt;MSH&amp;gt;$a&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;&lt;br /&gt;MSH&amp;gt;$b&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;1&lt;/SPAN&gt;&lt;br /&gt;MSH&amp;gt;$c&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;2&lt;/SPAN&gt;&lt;br /&gt;MSH&amp;gt;$d&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;5&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;6&lt;/SPAN&gt;&lt;br /&gt;&lt;SPAN style="COLOR: maroon"&gt;7&lt;/SPAN&gt;&lt;br /&gt;MSH&amp;gt;$e&lt;br /&gt;MSH&amp;gt;$d.getType().Name&lt;br /&gt;ArrayList&lt;br /&gt;MSH&amp;gt;$e.getType().Name&lt;br /&gt;You cannot call a method on a &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;-valued expression.&lt;br /&gt;At line:&lt;SPAN style="COLOR: maroon"&gt;1&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;char&lt;/SPAN&gt;:&lt;SPAN style="COLOR: maroon"&gt;11&lt;/SPAN&gt;&lt;br /&gt;+ $e.getType( &amp;lt;&amp;lt;&amp;lt;&amp;lt; ).Name&lt;/PRE&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;First 3 return values(0, 1, 2) were caused by the fact that &lt;a href="http://msdn2.microsoft.com/en-us/library/system.collections.arraylist.add.aspx"&gt;ArrayList&lt;/a&gt; returns "index at which the value has been added".&lt;br /&gt;Well, But then, what if you don't actually want to return indexes at which value has been added?&lt;br /&gt;&lt;br /&gt;There are two choices(and as far as I understand, they work about the same although the background principle is different)&lt;br /&gt;&lt;strong&gt;*EDIT*&lt;/strong&gt;: there are 3 choices( Thanks &lt;a href="http://mow001.blogspot.com"&gt;/\/\o\/\/&lt;/a&gt; for another solution :), Check out "comments" section )&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;[void]&lt;/strong&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;out-null&lt;/strong&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;&amp;gt; $null&lt;/strong&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[void]&lt;/strong&gt; in front of a method indicates that, the method does not return a value.&lt;br /&gt;For example, try out the following(yes, do try them out!)&lt;blockquote&gt;MSH&gt;[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")&lt;br /&gt;&lt;br /&gt;GAC    Version        Location&lt;br /&gt;---    -------        --------&lt;br /&gt;True   v2.0.50727     C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e08...&lt;br /&gt;MSH&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")&lt;br /&gt;MSH&gt;[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null&lt;br /&gt;MSH&gt;[System.Reflection.Assembly]::LoadWithPartialName("system.windows.forms") &gt;$null&lt;br /&gt;MSH&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Let's see what just happened &lt;ul&gt; &lt;li&gt;Calling &lt;a href="http://msdn2.microsoft.com/en-us/library/system.reflection.assembly.Loadwithpartialname"&gt;Assembly.LoadWithPartialName&lt;/a&gt; return the loaded assembly and the result is returned.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Looking at the second "[void]Assembly.LoadWithPartialName", you can tell that it didn't return anything(although Assembly is still loaded)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Third command also did not return anything(Well technically it did return something but it was sent to null)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Fourth command, you are sending output to null in different fashion.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Now Let's revise the function "bar".&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;MSH&amp;gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; bar {&lt;br /&gt;&amp;gt;&amp;gt; $arr = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Collections.ArrayList&lt;br /&gt;&amp;gt;&amp;gt; [void]$arr.Add(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;)&lt;br /&gt;&amp;gt;&amp;gt; [void]$arr.Add(&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;)&lt;br /&gt;&amp;gt;&amp;gt; [void]$arr.Add(&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;)&lt;br /&gt;&amp;gt;&amp;gt; &lt;br /&gt;&amp;gt;&amp;gt; &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; $arr&lt;br /&gt;&amp;gt;&amp;gt; }&lt;br /&gt;&amp;gt;&amp;gt; &lt;br /&gt;MSH&amp;gt;bar&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre&gt;MSH&amp;gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; bar {&lt;br /&gt;&amp;gt;&amp;gt; $arr = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Collections.ArrayList&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;) | out-null&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;) | out-null&lt;br /&gt;&amp;gt;&amp;gt; $arr.Add(&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;) | out-null&lt;br /&gt;&amp;gt;&amp;gt; &lt;br /&gt;&amp;gt;&amp;gt; &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; $arr&lt;br /&gt;&amp;gt;&amp;gt; }&lt;br /&gt;&amp;gt;&amp;gt; &lt;br /&gt;MSH&amp;gt;bar&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now those functions did not return added index positions during "ArrayList.Add" operations.&lt;br /&gt;I tend to go with &lt;strong&gt;[void]&lt;/strong&gt; since it sounds technically right to mark(or cast, not sure about how to call it) a method as not returning any value&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114067362994754644?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114067362994754644/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114067362994754644' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114067362994754644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114067362994754644'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/02/msh-how-to-avoid-returning-multiple.html' title='[MSH] How to a[void] returning multiple values from a function'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114053394781319762</id><published>2006-02-21T09:56:00.000-05:00</published><updated>2006-02-21T10:01:49.516-05:00</updated><title type='text'>Blogger and Technoroti problem</title><content type='html'>Well, it seems like a lot of people's updated Blogger posts are not being updated in &lt;a href="http://www.technorati.com"&gt;Technorati&lt;/a&gt; because of some problem on &lt;a href="http://www.blogger.com"&gt;Blogger.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have seemed to fixed it by going to my &lt;strong&gt;Technorati account -&gt; Your Blogs -&gt; View &amp; Edit Blog All Blog Info -&gt; Update Ping&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;It was kind of annoying not to be able to see other MSH and Monad posts being updated :)&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/blogger" rel="tag"&gt;Blogger&lt;/a&gt; &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114053394781319762?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114053394781319762/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114053394781319762' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114053394781319762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114053394781319762'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/02/blogger-and-technoroti-problem.html' title='Blogger and Technoroti problem'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-114030379044435195</id><published>2006-02-18T17:59:00.000-05:00</published><updated>2006-02-18T18:47:32.293-05:00</updated><title type='text'>[MSH] print-image *Snapin* version</title><content type='html'>During my spare time, i spent sometime converting "print-image" cmdlet into a Snapin version.&lt;br /&gt;&lt;br /&gt;I have extended its functionality just by a tiny bit by adding "Landscape" mode printing.  Well, I still haven't tried adding a "help" file yet so I will try to add one when I have more time(so for now, something like "print-image -?" will complain that cmdlet cannot find a help xml file).&lt;br /&gt;&lt;br /&gt;Anyways, here is the usage for "print-image" for this this version.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;This command also supports only one ubiquitous parameter: -Verbose(-vb)&lt;br /&gt;&lt;br /&gt;print-image [-FileName|-fn] System.String [[-Printer|-p|-pn] System.String] [[-Landscape|-l|-ls] System.Boolean]&lt;br /&gt;&lt;/blockquote&gt;Where,&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;FileName&lt;/strong&gt;: Fully Qualified File Name&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Printer&lt;/strong&gt;: Name of print to send image to&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;Landscape&lt;/strong&gt;: Print images in Landscape mode&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;Well, if you would like to change "margins", there are two options. First one is you go to your printer setting and change the margin size there, or modify the msh script to be able to receive margin data.&lt;br /&gt;&lt;br /&gt;To retrieve available printer names on your current machine, you can load "System.Drawing" assembly and then retrieve &lt;a href="http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref11/html/P_System_Drawing_Printing_PrinterSettings_InstalledPrinters.asp"&gt;"System.Drawing.Printing.PrinterSettings.InstalledPrinters"&lt;/a&gt; property like the following&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;MSH&gt;[reflection.assembly]::loadwithpartialname("system.drawing")&lt;br /&gt;&lt;br /&gt;GAC    Version        Location&lt;br /&gt;---    -------        --------&lt;br /&gt;True   v2.0.50727     C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\Syst...&lt;br /&gt;&lt;br /&gt;MSH&gt;[Drawing.Printing.PrinterSettings]::InstalledPrinters&lt;br /&gt;Microsoft Office Document Image Writer&lt;br /&gt;HP LaserJet 8150 PCL 5e&lt;br /&gt;HP LaserJet 5000 Series PCL 5e&lt;br /&gt;HP Color LaserJet 5500 PCL6(Color)&lt;br /&gt;Adobe PDF&lt;br /&gt;MSH&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;and then use the printer names listed above&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is how you can use the "print-image"&lt;br /&gt;&lt;a href="http://photobucket.com" target="_blank"&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/blogger/print-image-snapin.gif" border="0" alt="Image hosting by Photobucket"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Uhm, I don't have any storage areas where I can just put my source or compiled binaries on...  So, i am just pasting the source here...&lt;br /&gt;&lt;blockquote&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.IO;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Drawing;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Drawing.Printing;&lt;br /&gt;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.ComponentModel;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Management.Automation;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Collections.Generic;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Text;&lt;br /&gt;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; D2D.Snapins&lt;br /&gt;{&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// Prints image files&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;remarks&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// @TODO: Display Preview form&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    [RunInstaller(&lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;)]&lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; PrintImageSnapin : MshSnapIn&lt;br /&gt;    {&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Description&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"Prints an image file"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Name&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"D2D_print-image"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Vendor&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"DontBotherMeWithSpam"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    [Cmdlet(&lt;SPAN style="COLOR: maroon"&gt;"print"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;"image"&lt;/SPAN&gt;)]          &lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; PrintImageCommand : MshCmdlet&lt;br /&gt;    {&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;#region&lt;/SPAN&gt; Private Member Variables&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Fully qualified image file name to print&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; fileName;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Name of printer to use&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; printer;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Should we use landscape mode or not&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; landscape;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Responsible for printing image document&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; PrintDocument doc;&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Image to constructed from input file name&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Bitmap img;&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Holds exception thrown in functions other than &lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// "BeginProcessing", "EndProcessing", "ProcessRecord"&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Exception ex;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;#endregion&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;#region&lt;/SPAN&gt; MSH Parameters&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Fully qualified image file name to print&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        [Alias(&lt;SPAN style="COLOR: maroon"&gt;"fn"&lt;/SPAN&gt;)]&lt;br /&gt;        [Parameter(Mandatory = &lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;, Position = &lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, ValueFromPipeline = &lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;,&lt;br /&gt;            HelpMessage = &lt;SPAN style="COLOR: maroon"&gt;"Fully qualified image file name to print"&lt;/SPAN&gt;)]&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; FileName&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.fileName; }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.fileName = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Name of printer to use&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        [Alias(&lt;SPAN style="COLOR: maroon"&gt;"p"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;"pn"&lt;/SPAN&gt;)]&lt;br /&gt;        [Parameter(Mandatory = &lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;, Position = &lt;SPAN style="COLOR: maroon"&gt;1&lt;/SPAN&gt;, ValueFromPipeline = &lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;,&lt;br /&gt;            HelpMessage = &lt;SPAN style="COLOR: maroon"&gt;"Name of printer to print image"&lt;/SPAN&gt;)]&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Printer&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.printer; }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.printer = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        [Alias(&lt;SPAN style="COLOR: maroon"&gt;"l"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;"ls"&lt;/SPAN&gt;)]&lt;br /&gt;        [Parameter(Mandatory = &lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;, Position = &lt;SPAN style="COLOR: maroon"&gt;2&lt;/SPAN&gt;, ValueFromPipeline = &lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;,&lt;br /&gt;            HelpMessage = &lt;SPAN style="COLOR: maroon"&gt;"Toggle Landscape mode"&lt;/SPAN&gt;)]&lt;br /&gt;        [DefaultValue(&lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;)]&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; Landscape&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.landscape; }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.landscape = value; }&lt;br /&gt;        }&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;#endregion&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; EndProcessing()&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; PrintDocument();&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.BeginPrint += &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; PrintEventHandler(doc_BeginPrint);&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.PrintPage += &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; PrintPageEventHandler(doc_PrintPage);&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.EndPrint += &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; PrintEventHandler(doc_EndPrint);&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.Print();&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;#region&lt;/SPAN&gt; PrintDocument Event Handlers&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Construct image to print&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;param name="sender"&amp;gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;param name="e"&amp;gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; doc_BeginPrint(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; sender, PrintEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: green"&gt;// Construct image to print&lt;/SPAN&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.img = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; Bitmap(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.FileName);&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.DocumentName = Path.GetFileName(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.FileName);&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.DefaultPageSettings.Landscape = &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.Landscape;&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.Printer != &lt;SPAN style="COLOR: maroon"&gt;""&lt;/SPAN&gt;)&lt;br /&gt;                {&lt;br /&gt;                    &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.PrinterSettings.PrinterName = &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.Printer;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt; (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// We have failed create an image from the given file name&lt;/SPAN&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// No need to process any further, actually... &lt;/SPAN&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: gray"&gt;/// How do i abort the script at this point?&lt;/SPAN&gt;&lt;br /&gt;                ErrorRecord err = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ErrorRecord(ex, &lt;SPAN style="COLOR: maroon"&gt;"doc_BeginPrintError"&lt;/SPAN&gt;,&lt;br /&gt;                    ErrorCategory.InvalidData, &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.fileName);&lt;br /&gt;                WriteError(err);&lt;br /&gt;&lt;br /&gt;                e.Cancel = &lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;;    &lt;SPAN style="COLOR: green"&gt;// abort printing job&lt;/SPAN&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: green"&gt;//e.PrintAction = this.PrintAction;&lt;/SPAN&gt;&lt;br /&gt;            e.Cancel = &lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;;&lt;br /&gt;&lt;br /&gt;            WriteVerbose(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;.Format(&lt;br /&gt;                &lt;SPAN style="COLOR: maroon"&gt;"==================== {0} ===================="&lt;/SPAN&gt;,&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.DocumentName));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Print constructed image according to PrintAction&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; doc_PrintPage(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; sender, PrintPageEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            WriteVerbose(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;.Format(&lt;SPAN style="COLOR: maroon"&gt;"Printing {0}"&lt;/SPAN&gt;,&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.DocumentName));&lt;br /&gt;&lt;br /&gt;            Graphics g = e.Graphics;&lt;br /&gt;            Rectangle paperBounds = e.MarginBounds;&lt;br /&gt;            SizeF adjSize = AdjustImageSize(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.img.Size, paperBounds);&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex == &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// Calculate source and destination sizes&lt;/SPAN&gt;&lt;br /&gt;                RectangleF destRec = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; RectangleF(paperBounds.Location, adjSize);&lt;br /&gt;                RectangleF srcRec = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; RectangleF(&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, img.Width, img.Height);&lt;br /&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// Print to according to "PrintAction"&lt;/SPAN&gt;&lt;br /&gt;                g.DrawImage(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.img, destRec, srcRec, GraphicsUnit.Pixel);&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                ErrorRecord err = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ErrorRecord(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex, &lt;SPAN style="COLOR: maroon"&gt;"AdjustImageSizeError"&lt;/SPAN&gt;,&lt;br /&gt;                    ErrorCategory.NotSpecified, &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;);&lt;br /&gt;                WriteError(err);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: green"&gt;// Nothing else to print...&lt;/SPAN&gt;&lt;br /&gt;            e.HasMorePages = &lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Clean up used resources&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; doc_EndPrint(&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; sender, PrintEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: green"&gt;// Free Bitmap resource&lt;/SPAN&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.img != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.img.Dispose();&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.img = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            WriteVerbose(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;.Format(&lt;br /&gt;                &lt;SPAN style="COLOR: maroon"&gt;"xxxxxxxxxxxxxxxxxxxx {0} xxxxxxxxxxxxxxxxxxxx"&lt;/SPAN&gt;,&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.doc.DocumentName));&lt;br /&gt;        }&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;#endregion&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Adjust image size to fit to the paper size&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;param name="imgSize"&amp;gt;Size of image to adjust to fit to paper size&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;param name="paperBound"&amp;gt;Bounding area of paper&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;returns&amp;gt;Adjusted size of image that fits on the paper&amp;lt;/returns&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;remarks&amp;gt;If image's width is bigger than its height, try to fit width, else fit height&amp;lt;/remarks&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; SizeF AdjustImageSize(Size imgSize, RectangleF paperBound)&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; fitWidth = (imgSize.Width &amp;gt; imgSize.Height);   &lt;SPAN style="COLOR: green"&gt;// Fit width or the height?&lt;/SPAN&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt; ratio = &lt;SPAN style="COLOR: maroon"&gt;1&lt;/SPAN&gt;;&lt;br /&gt;            SizeF adjSize = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; SizeF(imgSize.Width, imgSize.Height);  &lt;SPAN style="COLOR: green"&gt;// adjusted size to return&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// Image size is smaller than actual paper size to print on,&lt;/SPAN&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// so we use the original image's size&lt;/SPAN&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ((imgSize.Width &amp;gt; paperBound.Width) &amp;amp;&amp;amp;&lt;br /&gt;                    (imgSize.Height &amp;gt; paperBound.Height))&lt;br /&gt;                {&lt;br /&gt;                    &lt;SPAN style="COLOR: green"&gt;// If width is longer than the height of its image,&lt;/SPAN&gt;&lt;br /&gt;                    &lt;SPAN style="COLOR: green"&gt;// we get the ratio of the width, else get the ratio of the height&lt;/SPAN&gt;&lt;br /&gt;                    &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ((fitWidth == &lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;))&lt;br /&gt;                    {&lt;br /&gt;                        ratio = (&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;)(paperBound.Width / imgSize.Height);&lt;br /&gt;                    }&lt;br /&gt;                    &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;br /&gt;                    {&lt;br /&gt;                        ratio = (&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;)(paperBound.Height / imgSize.Height);&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    adjSize = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; SizeF(&lt;br /&gt;                        &lt;SPAN style="COLOR: green"&gt;// Flip the width of the image in Landscape mode&lt;/SPAN&gt;&lt;br /&gt;                        (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.Landscape ? paperBound.Height : paperBound.Width),&lt;br /&gt;                        (&lt;SPAN style="COLOR: blue"&gt;float&lt;/SPAN&gt;)(imgSize.Height * ratio));&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt; (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex = ex;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; adjSize;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-114030379044435195?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/114030379044435195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=114030379044435195' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114030379044435195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/114030379044435195'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/02/msh-print-image-snapin-version.html' title='[MSH] print-image *Snapin* version'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113993300531057617</id><published>2006-02-14T10:57:00.000-05:00</published><updated>2006-02-17T21:31:44.523-05:00</updated><title type='text'>[MSH] print-image</title><content type='html'>Your boss comes at your desk with a pile of CDs filled with high quality tiff images(roughly 20000 x 20000 pixels)&lt;br /&gt;He tells you to print all the image files fit into a "letter" sized paper in 2 days&lt;br /&gt;&lt;br /&gt;Well, that sort of stuff happend to me...&lt;br /&gt;&lt;br /&gt;Man, was I frusted... &lt;br /&gt;&lt;br /&gt;But that's when MSH came into rescue~&lt;br /&gt;Well, the first thing that came up in my head was, "out-printer" cmdlet.&lt;br /&gt;So I tried the following&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;MSH&gt;$bitmap = new-object System.Drawing.Bitmap c:\test.tif&lt;br /&gt;MSH&gt;out-printer -printer "Adobe PDF" -in $bitmap&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Voila.  Now i was excited to see a picture in PDF format through "out-printer".&lt;br /&gt;Wrong!&lt;br /&gt;&lt;br /&gt;All I saw in the generated PDF file was&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;Tag                  :&lt;br /&gt;PhysicalDimension    : {Width=14454, Height=21957}&lt;br /&gt;Size                 : {Width=14454, Height=21957}&lt;br /&gt;Width                : 14454&lt;br /&gt;Height               : 21957&lt;br /&gt;HorizontalResolution : 1016&lt;br /&gt;VerticalResolution   : 1016&lt;br /&gt;Flags                : 77888&lt;br /&gt;RawFormat            : [ImageFormat: b96b3cb1-0728-11d3-9d7b-0000f81ef32e]&lt;br /&gt;PixelFormat          : Format1bppIndexed&lt;br /&gt;Palette              : System.Drawing.Imaging.ColorPalette&lt;br /&gt;FrameDimensionsList  : {7462dc86-6180-4c7e-8e3f-ee7333a7a483}&lt;br /&gt;PropertyIdList       : {256, 257, 258, 259, 262, 270, 273, 277, 278, 279, 282, 283, 32781}&lt;br /&gt;PropertyItems        : {256, 257, 258, 259, 262, 270, 273, 277, 278, 279, 282, 283, 32781}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;, which is data you see just typing "MSH&gt;$bitmap" in console.&lt;br /&gt;&lt;br /&gt;Gosh, was I frusted, again.  I looked into "out-printer" help page if there was some kind of "-encoding" option to print binary files(images) but there wans't any...&lt;br /&gt;&lt;br /&gt;I resorted to using &lt;a href="http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref11/html/N_System_Drawing_Printing.asp"&gt;System.Drawing.Printing.PrintDocument&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Well, using that Class, printing is an image is a breezy job&lt;br /&gt;So i created a cmdlet called "print-image" which takes an image name and print it &lt;br /&gt;&lt;br /&gt;Here is the usage of the cmdlet&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;print-image "image name" [printer name] [fit image to paper]&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The cmdlet takes the mandatory parameter "image name" with optional printer to print to and whether image size should fit on a paper&lt;br /&gt;&lt;br /&gt;Following is how the cmdlet can be used&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;MSH&gt; ls *.tif | foreach { print-image $_ }&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Well and that's exactly what i did... :)&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tr width="600"&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;function&lt;/SPAN&gt; print-image {&lt;br /&gt; param([&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;]$imageName = $(throw &lt;SPAN style="COLOR: maroon"&gt;"Enter image name to print"&lt;/SPAN&gt;),&lt;br /&gt;    [&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;]$printer = &lt;SPAN style="COLOR: maroon"&gt;""&lt;/SPAN&gt;,&lt;br /&gt;    [&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;]$fitImageToPaper = $&lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;)&lt;br /&gt;&lt;br /&gt; trap { &lt;SPAN style="COLOR: blue"&gt;break&lt;/SPAN&gt;; }&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# check out Lee Holmes' blog(http://www.leeholmes.com/blog/HowDoIEasilyLoadAssembliesWhenLoadWithPartialNameHasBeenDeprecated.aspx)&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# on how to avoid using deprecated "LoadWithPartialName" function&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# To load assembly containing System.Drawing.Printing.PrintDocument&lt;/SPAN&gt;&lt;br /&gt; [&lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt;][System.Reflection.Assembly]::LoadWithPartialName(&lt;SPAN style="COLOR: maroon"&gt;"System.Drawing"&lt;/SPAN&gt;)&lt;br /&gt;&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# Bitmap image to use to print image&lt;/SPAN&gt;&lt;br /&gt; $bitmap = $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&lt;br /&gt;&lt;br /&gt; $doc = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; System.Drawing.Printing.PrintDocument&lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# if printer name not given, use default printer&lt;/SPAN&gt;&lt;br /&gt; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($printer -ne &lt;SPAN style="COLOR: maroon"&gt;""&lt;/SPAN&gt;) {&lt;br /&gt;  $doc.PrinterSettings.PrinterName = $printer&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; $doc.DocumentName = [System.IO.Path]::GetFileName($imageName)&lt;br /&gt;&lt;br /&gt; $doc.add_BeginPrint({&lt;br /&gt;  Write-Host &lt;SPAN style="COLOR: maroon"&gt;"==================== $($doc.DocumentName) ===================="&lt;/SPAN&gt;&lt;br /&gt; })&lt;br /&gt; &lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# clean up after printing...&lt;/SPAN&gt;&lt;br /&gt; $doc.add_EndPrint({&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($bitmap -ne $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;) {&lt;br /&gt;   $bitmap.Dispose()&lt;br /&gt;   $bitmap = $&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;&lt;br /&gt;  }&lt;br /&gt;  Write-Host &lt;SPAN style="COLOR: maroon"&gt;"xxxxxxxxxxxxxxxxxxxx $($doc.DocumentName) xxxxxxxxxxxxxxxxxxxx"&lt;/SPAN&gt;&lt;br /&gt; })&lt;br /&gt; &lt;br /&gt; &lt;SPAN style="COLOR: green"&gt;# Adjust image size to fit into paper and print image&lt;/SPAN&gt;&lt;br /&gt; $doc.add_PrintPage({&lt;br /&gt;  Write-Host &lt;SPAN style="COLOR: maroon"&gt;"Printing $imageName..."&lt;/SPAN&gt;&lt;br /&gt; &lt;br /&gt;  $g = $_.Graphics&lt;br /&gt;  $pageBounds = $_.MarginBounds&lt;br /&gt;  $img = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; Drawing.Bitmap($imageName)&lt;br /&gt;  &lt;br /&gt;  $adjustedImageSize = $img.Size&lt;br /&gt;  $ratio = [&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;] &lt;SPAN style="COLOR: maroon"&gt;1&lt;/SPAN&gt;;&lt;br /&gt;  &lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# Adjust image size to fit on the paper&lt;/SPAN&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($fitImageToPaper) {&lt;br /&gt;   $fitWidth = [&lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;] ($img.Size.Width &amp;gt; $img.Size.Height)&lt;br /&gt;   &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (($img.Size.Width -le $_.MarginBounds.Width) -and&lt;br /&gt;    ($img.Size.Height -le $_.MarginBounds.Height)) {&lt;br /&gt;    $adjustedImageSize = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; System.Drawing.SizeF($img.Size.Width, $img.Size.Height)&lt;br /&gt;   } &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt; {&lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; ($fitWidth) {&lt;br /&gt;     $ratio = [&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;] ($_.MarginBounds.Width / $img.Size.Width);&lt;br /&gt;    } &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt; {&lt;br /&gt;     $ratio = [&lt;SPAN style="COLOR: blue"&gt;double&lt;/SPAN&gt;] ($_.MarginBounds.Height / $img.Size.Height)&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    $adjustedImageSize = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; System.Drawing.SizeF($_.MarginBounds.Width, [&lt;SPAN style="COLOR: blue"&gt;float&lt;/SPAN&gt;]($img.Size.Height * $ratio))&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# calculate destination and source sizes&lt;/SPAN&gt;&lt;br /&gt;  $recDest = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; Drawing.RectangleF($pageBounds.Location, $adjustedImageSize)&lt;br /&gt;  $recSrc = new-&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; Drawing.RectangleF(&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, $img.Width, $img.Height)&lt;br /&gt;  &lt;br /&gt;  &lt;SPAN style="COLOR: green"&gt;# Print to the paper&lt;/SPAN&gt;&lt;br /&gt;  $_.Graphics.DrawImage($img, $recDest, $recSrc, [Drawing.GraphicsUnit]&lt;SPAN style="COLOR: maroon"&gt;"Pixel"&lt;/SPAN&gt;)&lt;br /&gt;  &lt;br /&gt;  $_.HasMorePages = $&lt;SPAN style="COLOR: maroon"&gt;false&lt;/SPAN&gt;; &lt;SPAN style="COLOR: green"&gt;# nothing else to print&lt;/SPAN&gt;&lt;br /&gt; })&lt;br /&gt; &lt;br /&gt; $doc.Print()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;Oh yeah, I would appreciate it if anyone can tell me how i can format the code to fit on to the site :)&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113993300531057617?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113993300531057617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113993300531057617' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113993300531057617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113993300531057617'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/02/msh-print-image.html' title='[MSH] print-image'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113869036632611592</id><published>2006-01-31T00:44:00.000-05:00</published><updated>2006-02-18T01:31:28.076-05:00</updated><title type='text'>[MSH] Clipboard Snapin...</title><content type='html'>Thanks to both &lt;a href="http://mow001.blogspot.com/"&gt;/\/\o\/\/&lt;/a&gt; and &lt;a href="http://spaces.msn.com/keithhill/"&gt;Keith Hill&lt;/a&gt;, I was able to somewhat improve the Clipboard snapin by adding "Get-Clipboard" cmdlet.&lt;br /&gt;&lt;br /&gt;I was able to fix "Out-Clipboard" cmdlet to receive an input from pipe by setting type of "inputData" to that of "string" from "object"(thanks /\/\o\/\/).&lt;br /&gt;&lt;br /&gt;Well, I just couldn't improve much from Keith's orignal &lt;a href="http://home.comcast.net/~rkeithhill/MSH/Clipboard.cs"&gt;Clipboard Cmdlet&lt;/a&gt; other than the fact that this is now a Snapin and fixed one small bug(refer to OutClipboardCommand.SetObject)...&lt;br /&gt;&lt;br /&gt;Anyways, here is how this Clipboard Snapin can be used&lt;br /&gt;&lt;br /&gt;Here is a simple one.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;MSH&gt; "Hello, World!" | Out-Clipboard&lt;br /&gt;MSH&gt; Get-Clipboard&lt;br /&gt;Hello, World!&lt;br /&gt;MSH&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now let's try to send the output of "get-process" to the clipboard&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;MSH&gt; get-process | Out-Clipboard&lt;br /&gt;MSH&gt; Get-Clipboard&lt;br /&gt;System.Diagnostics.Process (ahnsd)&lt;br /&gt;System.Diagnostics.Process (ahnsdsv)&lt;br /&gt;...&lt;br /&gt;System.Diagnostics.Process (winlogon)&lt;br /&gt;System.Diagnostics.Process (wmiprvse)&lt;br /&gt;MSH&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now, what is going on here?  Well, I don't want to go too deep with that because it was explained in Keith's blog on &lt;a href="http://spaces.msn.com/keithhill/blog/cns!5A8D2641E0963A97!193.entry"&gt;MSH: Get-Clipboard and Set-Clipboard Cmdlets&lt;/a&gt; already.&lt;br /&gt;&lt;br /&gt;Anyways, the problem is that, "out-clipboard" is receiving unformatted input string so MSH user have to explicitly have to convert piped data to string (through "out-string") before sending the data to Out-Clipboard(well, that is why the cmdlet only supports data of type string, for now)&lt;br /&gt;&lt;br /&gt;So, i was searching and reading documents on MSDN and was looking for ways to put that "out-string" behavior inside "out-clipboard".  Well, I haven't found the answer yet...  It seems like there is not "a recommanded way invoking a cmdlet that is a subclass of MshCmdlet from another cmdlet" according to Kevin Loo who also suggested me to create a new function defined like the following &lt;br /&gt;&lt;blockquote&gt;function set-clipboard {$input | out-string | out-clipboard}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Using "set-clipboard", try to run "get-process | set-clipboard", "get-childitem | set-clipboard", etc...  But the problem with "set-clipboard" approach is that, you can't explicitly pass the object to "set-clipboard"... while something like "out-clipboard $(dir)" would work(although not how you might expect it to work).&lt;br /&gt;I guess a workaround for that problem might be my next topic...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For instructions on how to compile and install the snapin, please refer to Appendix D in "Getting Started" document for MSH.&lt;br /&gt;&lt;br /&gt;Here is how to load Clipboard Snapin&lt;br /&gt;&lt;blockquote&gt;MSH&gt; set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil&lt;br /&gt;MSH&gt; cd [go to Snapin assembly directory]&lt;br /&gt;MSH&gt; installutil Snapins.dll&lt;br /&gt;MSH&gt; get-mshsnapin -r&lt;br /&gt;Name        : ClipboardSnapin&lt;br /&gt;MshVersion  : 1.0&lt;br /&gt;Description : Provides retrieving/sending data from/to Clipboard&lt;br /&gt;MSH&gt; add-mshsnapin ClipboardSnapin&lt;br /&gt;&lt;/blockquote&gt;Now,  ClipboardSnapin is loaded and you are good to go.&lt;br /&gt;&lt;br /&gt;Well, the source's below... but I was deliberately trying to make each line shortern than 80 columns... so it looks longer than it should be...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Text;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.ComponentModel;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Threading;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Windows.Forms;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Management.Automation;&lt;br /&gt;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; D2D.Snapins&lt;br /&gt;{&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// Define basic information of this snap in&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    [RunInstaller(&lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;)]&lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; ClipboardSnapin : MshSnapIn&lt;br /&gt;    {&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; ClipboardSnapin() : &lt;SPAN style="COLOR: blue"&gt;base&lt;/SPAN&gt;()&lt;br /&gt;        {&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Name&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"ClipboardSnapin"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Vendor&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"DontBotherMeWithSpam"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Description&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"Provides retrieving/sending data from/to Clipboard"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// Cmdlet to return clipboard text to pipe&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;remarks&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// Original Author: Keith Hill (http://spaces.msn.com/keithhill)&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// Original Source URL: http://home.comcast.net/~rkeithhill/MSH/Clipboard.cs&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// Modified by: DBMwS&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// Date: 01/31/2006 @ 12:59AM&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// Removed, "timeout" feature&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    [Cmdlet(&lt;SPAN style="COLOR: maroon"&gt;"Get"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;"Clipboard"&lt;/SPAN&gt;)]&lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; GetClipboardCommand : Cmdlet&lt;br /&gt;    {&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Exception ex;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; dataObject = &lt;SPAN style="COLOR: maroon"&gt;""&lt;/SPAN&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; BeginProcessing()&lt;br /&gt;        {&lt;br /&gt;            Thread t = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; Thread(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ThreadStart(GetObject));&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                t.SetApartmentState(ApartmentState.STA);&lt;br /&gt;                t.Start();&lt;br /&gt;                t.Join();&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt; (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                ErrorRecord err = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ErrorRecord(ex, &lt;SPAN style="COLOR: maroon"&gt;"GetClipboardError"&lt;/SPAN&gt;,&lt;br /&gt;                    ErrorCategory.NotSpecified, t);&lt;br /&gt;                WriteError(err);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;br /&gt;            {&lt;br /&gt;                WriteError(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ErrorRecord(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex, &lt;br /&gt;                    &lt;SPAN style="COLOR: maroon"&gt;"GetClipboard::GetObjectError"&lt;/SPAN&gt;, &lt;br /&gt;                    ErrorCategory.NotSpecified, &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;));&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            WriteVerbose(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;.Format(&lt;SPAN style="COLOR: maroon"&gt;"Sending '{0}' to pipe"&lt;/SPAN&gt;, &lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.dataObject.ToString()));&lt;br /&gt;            WriteObject(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.dataObject, &lt;br /&gt;                (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.dataObject.GetType().IsArray));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; GetObject()&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.dataObject = Clipboard.GetText();&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt; (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex = ex;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// send output string to clipboard&lt;/SPAN&gt;&lt;br /&gt;    &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;    [Cmdlet(&lt;SPAN style="COLOR: maroon"&gt;"Out"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;"Clipboard"&lt;/SPAN&gt;)]&lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; OutClipboardCommand : Cmdlet&lt;br /&gt;    {&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Unhandled exception&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Exception ex;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Actuall worker thread&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Thread t;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Holds all the necessary input data to send to Clipboard&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; StringBuilder sb = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; StringBuilder();&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Input data received either from pipe or as an argument&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; []inputData;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Input data to send to clipboard&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        [Parameter(Mandatory = &lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;, Position = &lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, ValueFromPipeline = &lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;)]&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; []InputData&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; inputData; }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; { inputData = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Create a STA thread to start later on.&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; BeginProcessing()&lt;br /&gt;        {&lt;br /&gt;            WriteVerbose(&lt;SPAN style="COLOR: maroon"&gt;"Begin Processing(Creating a new STA thread)..."&lt;/SPAN&gt;);&lt;br /&gt;&lt;br /&gt;            t = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; Thread(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ThreadStart(SetObject));&lt;br /&gt;            t.SetApartmentState(ApartmentState.STA);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Append all input lines into one&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// (with a newline appended for each input data)&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ProcessRecord()&lt;br /&gt;        {&lt;br /&gt;            WriteVerbose(&lt;SPAN style="COLOR: maroon"&gt;"Processing Record..."&lt;/SPAN&gt;);&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.InputData != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;br /&gt;                {&lt;br /&gt;                    WriteVerbose(&lt;br /&gt;                        &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;.Format(&lt;SPAN style="COLOR: maroon"&gt;"\tAppending {0}"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.InputData));&lt;br /&gt;                    &lt;SPAN style="COLOR: blue"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; line &lt;SPAN style="COLOR: blue"&gt;in&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.InputData)&lt;br /&gt;                    {&lt;br /&gt;                        &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.sb.AppendLine(line);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt; (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// Well I don't know what happened, &lt;/SPAN&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// so send the error to the host...&lt;/SPAN&gt;&lt;br /&gt;                ErrorRecord err = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ErrorRecord(ex, &lt;SPAN style="COLOR: maroon"&gt;"OutClipboardError"&lt;/SPAN&gt;, &lt;br /&gt;                    ErrorCategory.NotSpecified, t);&lt;br /&gt;                WriteError(err);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Start a thread to send input data to Clipboard&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; EndProcessing()&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                t.Start();&lt;br /&gt;                t.Join();&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt; (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                ErrorRecord err = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ErrorRecord(ex, &lt;SPAN style="COLOR: maroon"&gt;"OutClipboardError"&lt;/SPAN&gt;, &lt;br /&gt;                    ErrorCategory.NotSpecified, t);&lt;br /&gt;                WriteError(err);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: green"&gt;// Handle error occurred while sending text to clipboard&lt;/SPAN&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: green"&gt;// Well, try out something as stupid as "clear-host | out-clipboard"...&lt;/SPAN&gt;&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)&lt;br /&gt;            {&lt;br /&gt;                WriteError(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ErrorRecord(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex, &lt;br /&gt;                    &lt;SPAN style="COLOR: maroon"&gt;"OutClipboard::SetObjectError"&lt;/SPAN&gt;, &lt;br /&gt;                    ErrorCategory.NotSpecified, &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;));&lt;br /&gt;            }&lt;br /&gt;            WriteVerbose(&lt;SPAN style="COLOR: maroon"&gt;"End Processing..."&lt;/SPAN&gt;);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Send input data to clipboard&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; SetObject()&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;try&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// Before sending the inputData to clipboard, &lt;/SPAN&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: green"&gt;// we need to drop the last newline character&lt;/SPAN&gt;&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; text = &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.sb.ToString();&lt;br /&gt;                text = text.Substring(&lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, &lt;br /&gt;                    (text.Length - System.Environment.NewLine.Length));&lt;br /&gt;&lt;br /&gt;                Clipboard.SetText(text);&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;catch&lt;/SPAN&gt; (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.ex = ex;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113869036632611592?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113869036632611592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113869036632611592' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113869036632611592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113869036632611592'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/01/msh-clipboard-snapin.html' title='[MSH] Clipboard Snapin...'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113847682650416244</id><published>2006-01-28T14:22:00.000-05:00</published><updated>2006-02-18T01:31:09.890-05:00</updated><title type='text'>[MSH Snapin] Need help implementing Out-Clipboard Snapin</title><content type='html'>Well, while playing around with new MSH beta 3 feature, MSH Snapin, I came across with /\/\o\/\/'s &lt;a href="http://mow001.blogspot.com/2005/10/msh-clipboard-use-workaround.html"&gt;MSH Clipboard use workaround&lt;/a&gt; blog.&lt;br /&gt;&lt;br /&gt;Since, Msh engine is created using Muti-Thread Apartment model, it's still not possible to create or use an object that requires STA.  /\/\o\/\/'s solution uses in-memory compilation and dynamic object instantiation using CodeDom namespace.&lt;br /&gt;&lt;br /&gt;Well, since we have a new Snapin feature, I have decided to create my own "out-clipboard" cmdlet.&lt;br /&gt;&lt;br /&gt;In the topic i have mentioned that, there is some problems with the Snapin.  I can't seem to get an input to be passed from pipe although I have specified "ValueFromPipeline=true" in "Parameter" attribute.  Oh well, it is far from being complete, but posting about this code to ask about the problem and how I should be improving it at usenet or at forums...&lt;br /&gt;&lt;br /&gt;So far, only sending text to clipboard works...&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;MSH&gt;Out-Clipboard "Hello, World"&lt;br /&gt;Begin Processing...&lt;br /&gt;Processing Record...&lt;br /&gt;Setting String&lt;br /&gt;End Processing...&lt;br /&gt;MSH&gt;"Hello, World" | Out-Clipboard&lt;br /&gt;Begin Processing...&lt;br /&gt;Processing Record...&lt;br /&gt;Setting MshObject&lt;br /&gt;End Processing...&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;I have pasted "Hello, World" in the second MSH prompt through mouse and then piped the data to "out-clipboard".  The first case works while the latter case doesn't as I have mentioned above...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Comment on source:&lt;/strong&gt;&lt;br /&gt;This snapin basically creates a new STA thread and send input argument to clipboard through callback.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Threading;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Windows.Forms;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.ComponentModel;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Management.Automation;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Collections.Generic;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System.Text;&lt;br /&gt;&lt;br /&gt;&lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; snapins&lt;br /&gt;{&lt;br /&gt;    [RunInstaller(&lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;)]&lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; OutClipboardSnapin : System.Management.Automation.MshSnapIn&lt;br /&gt;    {&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; OutClipboardSnapin() : &lt;SPAN style="COLOR: blue"&gt;base&lt;/SPAN&gt;()&lt;br /&gt;        {&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Name&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"OutClipboardSnapin"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Vendor&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"DontBotherMeWithSpam"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; Description&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: maroon"&gt;"This snapin receives piped output into Clipboard"&lt;/SPAN&gt;; }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    [Cmdlet(&lt;SPAN style="COLOR: maroon"&gt;"Out"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: maroon"&gt;"Clipboard"&lt;/SPAN&gt;)]&lt;br /&gt;    &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; OutClipboardCommand : Cmdlet&lt;br /&gt;    {&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; Thread t;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; inputData;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// Input data to send to clipboard&lt;/SPAN&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;&lt;br /&gt;        [Parameter(Mandatory = &lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;, Position = &lt;SPAN style="COLOR: maroon"&gt;0&lt;/SPAN&gt;, ValueFromPipeline=&lt;SPAN style="COLOR: maroon"&gt;true&lt;/SPAN&gt;)]&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; InputData&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; inputData; }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt; { inputData = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; BeginProcessing()&lt;br /&gt;        {&lt;br /&gt;            t = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; Thread(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ThreadStart(SetObject));&lt;br /&gt;            t.SetApartmentState(ApartmentState.STA);&lt;br /&gt;&lt;br /&gt;            WriteObject(&lt;SPAN style="COLOR: maroon"&gt;"Begin Processing..."&lt;/SPAN&gt;);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt;  ProcessRecord()&lt;br /&gt;        {&lt;br /&gt;            WriteObject(&lt;SPAN style="COLOR: maroon"&gt;"Processing Record..."&lt;/SPAN&gt;);&lt;br /&gt;            WriteObject(&lt;SPAN style="COLOR: maroon"&gt;"Setting "&lt;/SPAN&gt; + &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.InputData.GetType().Name);&lt;br /&gt;            t.Start();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; EndProcessing()&lt;br /&gt;        {&lt;br /&gt;            t.Join();&lt;br /&gt;            WriteObject(&lt;SPAN style="COLOR: maroon"&gt;"End Processing..."&lt;/SPAN&gt;);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; SetObject()&lt;br /&gt;        {&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.InputData.GetType() == &lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;))&lt;br /&gt;            {&lt;br /&gt;                Clipboard.SetText(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.InputData.ToString());&lt;br /&gt;            }&lt;br /&gt;            &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;br /&gt;            {&lt;br /&gt;                Clipboard.SetDataObject(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.InputData);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tags : &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113847682650416244?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113847682650416244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113847682650416244' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113847682650416244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113847682650416244'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/01/msh-snapin-need-help-implementing-out.html' title='[MSH Snapin] Need help implementing Out-Clipboard Snapin'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113747056221109968</id><published>2006-01-16T22:25:00.000-05:00</published><updated>2006-01-16T23:03:21.533-05:00</updated><title type='text'>Simple tools for complex jobs</title><content type='html'>While listening to "Inside the Net" podcast episode #5 "Jason Fried of 37Signals", I have realized something.&lt;br /&gt;&lt;br /&gt;As an application or scripts gets more mature, they tend to do more stuff than it supposed to do.  For an example, Adobe Photoshop is extremely bloated so that it includes a lot of functionalities that normal users are not even aware of.&lt;br /&gt;&lt;br /&gt;Now, we could come up with an analogy that, if you would want to disassemble, you would normally use screw drivers.  But if you have a Swiss Army knife, you do can get a job done but you would have to search for the right tool that's bundled with the Swiss Army Knife.  Swiss Army KNife can get other tasks accomplished but it's bloated.&lt;br /&gt;&lt;br /&gt;So what I am trying to accomplish in this Blog is that, I would like to create simple tools or scripts or functions to accomplish other many things.&lt;br /&gt;&lt;br /&gt;For example, when using Windows Forms, one would normally have to import &lt;a href="http://windowssdk.msdn.microsoft.com/library/en-us/cpref32/html/N_System_Windows_Forms.asp"&gt;"System.Windows.Forms"&lt;/a&gt; through excruciatingly long statement as followed.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;[System.Reflection.Assembly]::LoadWithPartialName(&lt;span style=' color: Maroon;'&gt;"System.Windows.Forms"&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Would you actually like to have multiple of those "[System.Reflection.Assembly]::LoadWithPartialName" functions in your script?&lt;br /&gt;Coming from a C# community, i could not stand such long function names clogging up my scripts.&lt;br /&gt;&lt;br /&gt;So I have created a such script like,&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; using-library {&lt;br /&gt;    param($ns = $(throw &lt;span style=' color: Maroon;'&gt;"Enter Namespace to import"&lt;/span&gt;), [&lt;span style=' color: Blue;'&gt;bool&lt;/span&gt;]$SuppressOutput = $&lt;span style=' color: Maroon;'&gt;false&lt;/span&gt;)&lt;br /&gt;    &lt;br /&gt;    trap { throw &lt;span style=' color: Maroon;'&gt;"Could not import Namespace $($ns)"&lt;/span&gt; }&lt;br /&gt;    &lt;br /&gt;    &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; ($SuppressOutput) {&lt;br /&gt;        [&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;][System.Reflection.Assembly]::LoadWithPartialName($ns)&lt;br /&gt;    } &lt;span style=' color: Blue;'&gt;else&lt;/span&gt; {&lt;br /&gt;        [System.Reflection.Assembly]::LoadWithPartialName($ns)&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;MSH&gt;Set-Alias using using-library&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now, in a script, one can simply use C# style "USE" statement in their scripts without having to know inner details on how to import and can simply concentrate on what his/her script needs to do.&lt;br /&gt;What is more great about such abstraction is that, since &lt;a href="http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref15/html/M_System_Reflection_Assembly_LoadWithPartialName_1_16219e3a.asp"&gt;"LoadWithPartialName"&lt;/a&gt; function is now obsolete according to WinFX document, one can simply change function implementation of "using-library" without having to change all scripts with "LoadWithPartial" name.&lt;br /&gt;&lt;br /&gt;Well, the predicament I am in now is, HOW can I put all the scripts in one place so that it'd be easy to to use all the functions, load them or unload them with ease.  Ah there is also a name collision issues that I have to cope with.  It'd be nice if MSH had one of those Namespace concepts as in .NET library.&lt;br /&gt;Tags : &lt;/span&gt;&lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113747056221109968?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113747056221109968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113747056221109968' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113747056221109968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113747056221109968'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/01/simple-tools-for-complex-jobs.html' title='Simple tools for complex jobs'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113713060711887858</id><published>2006-01-13T00:29:00.000-05:00</published><updated>2006-01-13T00:53:34.543-05:00</updated><title type='text'>[MSH] Change Default "Get-Credential" Prompt Behavior</title><content type='html'>&lt;a href="http://mow001.blogspot.com"&gt;/\/\o\/\/&lt;/a&gt; has pointed out that the default prompt mode for "get-content" in Monad Beta 3 is through "CredUI", meaning, if you type "get-content" in Monad Beta 3, &lt;br /&gt;you will see one of these familiar Windows Credential UI:&lt;br /&gt;&lt;br /&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/blogger/GuiPrompt.jpg" alt="Image hosted by Photobucket.com"&gt;&lt;br /&gt;&lt;br /&gt;According to &lt;span style="font-style:italic;"&gt;Abhishek Agrawal&lt;/span&gt; on Usenet post,&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;The default implementation for get-credential now uses the Windows CredUI&lt;br /&gt;functionality for collecting credentials. This is a requirement for being&lt;br /&gt;complaint with Windows Common Criteria.  We still retain the console mode&lt;br /&gt;which can be enabled by setting the registry key "ConsolePrompting" under&lt;br /&gt;HLKM:\SOFTWARE\Microsoft\MSH\1\ShellIds to  "True" (string)&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Ah, now, i go to &lt;span style="font-weight:bold;"&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSH\1\ShellIds&lt;/span&gt;(Well, I can see that Registry structure has been modified slightly from pre-Beta 3 version of Monad), you won't see a registry key named "ConsolePrompting".  You can simply create that key and set the value to whichever mode you set the value of key to.  I prefer "GUI" mode so mine is set to "false".  But i just want to switch between two modes easily so created the following script that will simply change the prompt mode with a simple function(&lt;span style="font-style:italic;"&gt;SetConsoleCredPrompt&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style=' color: Red;'&gt;MSH&lt;/span&gt;&gt; SetConsoleCredPrompt&lt;br /&gt;Your Credential Prompting Mode has been changed to "&lt;span style=' color: Red;'&gt;Console&lt;/span&gt;" Mode.&lt;br /&gt;&lt;span style=' color: Red;'&gt;MSH&lt;/span&gt;&gt; SetConsoleCredPrompt($false)&lt;br /&gt;Your Credential Prompting Mode has been changed to "&lt;span style=' color: Green;'&gt;Gui&lt;/span&gt;" Mode.&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;SetConsoleCredPrompt&lt;/span&gt; simply navigates to &lt;span style="font-weight:bold;"&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSH\1\ShellIds&lt;/span&gt; and then change the value of "ConsolePrompt" to "true" or "false".&lt;br /&gt;&lt;br /&gt;This is one of the advantage of knowing how to script...  I don't have to do much manually by having to open up the registry editor, navigate to the right path and change the key(BTW, isn't Registry Provider just awesome or what?).&lt;br /&gt;&lt;br /&gt;Well the source? Nothing interesting about it...&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style=' color: Green;'&gt;# author: DBMwS&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;# date: 01/12/2005 @ 11:14 PM&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;# description: "Get-Credential" prompting method between "console" and "CredUI"&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;# note: Works only for Beta 3 of Monad&lt;/span&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; SetConsoleCredPrompt() {&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# default is $private:false since in Monad Beta 3, CredUI is the default way to&lt;/span&gt;&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# prompt end-user for entering username and password&lt;/span&gt;&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# But should i throw an Exception here or not... That's the problem...&lt;/span&gt;&lt;br /&gt;    param([&lt;span style=' color: Blue;'&gt;bool&lt;/span&gt;] $ConsoleMode = $private:&lt;span style=' color: Maroon;'&gt;true&lt;/span&gt;)&lt;br /&gt;    &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Ready for the unexpected...(such as running this script for non beta 3 version of Monad&lt;/span&gt;&lt;br /&gt;    trap { Write-Host &lt;span style=' color: Maroon;'&gt;"Some Unknown error has occurred, Aborting Mission..."&lt;/span&gt;; &lt;span style=' color: Blue;'&gt;return&lt;/span&gt;; }&lt;br /&gt;    &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# MSH Beta 3 ShellID&lt;/span&gt;&lt;br /&gt;    $private:path = [&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;] &lt;span style=' color: Maroon;'&gt;"HKLM:\SOFTWARE\Microsoft\MSH\1\ShellIds"&lt;/span&gt;&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# A new key name to create.&lt;/span&gt;&lt;br /&gt;    $private:key = [&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;] &lt;span style=' color: Maroon;'&gt;"ConsolePrompting"&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Check if the location we need to reach exists or not, else abort the script&lt;/span&gt;&lt;br /&gt;    &lt;span style=' color: Blue;'&gt;if&lt;/span&gt; (test-path $private:path) {&lt;br /&gt;        set-property $private:path -Property $private:key -Type &lt;span style=' color: Blue;'&gt;String&lt;/span&gt; -Value $ConsoleMode.ToString()&lt;br /&gt;    } &lt;span style=' color: Blue;'&gt;else&lt;/span&gt; {&lt;br /&gt;        throw &lt;span style=' color: Maroon;'&gt;"Could not find Registry Path($($private:path)) to change Creditial Prompt Setting`nMaybe you are running pre-beta3 MSH?"&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    Write-host -n &lt;span style=' color: Maroon;'&gt;"Your Credential Prompting Mode has been changed to `""&lt;/span&gt; &lt;br /&gt;    &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;($ConsoleMode) { Write-host -n -f &lt;span style=' color: Maroon;'&gt;"red"&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;"Console"&lt;/span&gt; } &lt;span style=' color: Blue;'&gt;else&lt;/span&gt; { Write-Host -n -f &lt;span style=' color: Maroon;'&gt;"green"&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;"Gui"&lt;/span&gt; }&lt;br /&gt;    Write-host &lt;span style=' color: Maroon;'&gt;"`" Mode."&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Tags : &lt;/span&gt;&lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113713060711887858?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113713060711887858/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113713060711887858' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113713060711887858'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113713060711887858'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/01/msh-change-default-get-credential.html' title='[MSH] Change Default &quot;Get-Credential&quot; Prompt Behavior'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113687501967336446</id><published>2006-01-10T01:12:00.000-05:00</published><updated>2006-01-10T01:54:00.160-05:00</updated><title type='text'>/\/\o\/\/ on MSH (Monad): Report MP3 count and size by User from MSH</title><content type='html'>&lt;a href="http://mow001.blogspot.com/2006/01/report-mp3-count-and-size-by-user-from.html"&gt;/\/\o\/\/ on MSH (Monad): Report MP3 count and size by User from MSH&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Just a great fun MSH script to play around with...  As the topic says, it simply reports MP3 file statistics... on either local machine or on a network computer, etc...&lt;br /&gt;&lt;br /&gt;But what is up with those @{expression=...;Name=...} stuff?&lt;br /&gt;&lt;br /&gt;&lt;iframe width = "600" height = "400" src="http://mow001.blogspot.com/2006/01/report-mp3-count-and-size-by-user-from.html"&gt;wow&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;If you scroll down a bit, then you will run into two of "select" cmdlets with weird arguments.&lt;br /&gt;Don't worry about it so much, argument is simply an array of a hashtable...&lt;br /&gt;&lt;br /&gt;So let's see...&lt;br /&gt;Let's take a look at,&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="color: green;"&gt;#&amp;nbsp;group&amp;nbsp;them&amp;nbsp;per&amp;nbsp;user&amp;nbsp;&lt;/span&gt; &lt;br&gt;&lt;br&gt;&lt;span style="color: maroon;"&gt;"`n$Extension&amp;nbsp;Per&amp;nbsp;User"&lt;/span&gt; &lt;br&gt;$Userfiles&amp;nbsp;|&amp;nbsp;group&amp;nbsp;Username&amp;nbsp;|&amp;nbsp;select&amp;nbsp;@{expression={$_.Name};Name=&lt;span style="color: maroon;"&gt;"User"&lt;/span&gt;}, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@{expression={($_.group&amp;nbsp;|&amp;nbsp;measure-&lt;span style="color: blue;"&gt;object&lt;/span&gt;).count};Name=&lt;span style="color: maroon;"&gt;"Count"&lt;/span&gt;}, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@{expression={($_.group&amp;nbsp;|&amp;nbsp;measure-&lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;nbsp;-property&amp;nbsp;RoundedSize&amp;nbsp;-sum).sum};Name=&lt;span style="color: maroon;"&gt;"MB"&lt;/span&gt;}&lt;br&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;you will just simply see an array of hashtable object with two keys with matching values&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;1st element&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;expression: {$_.Name}&lt;br /&gt;&lt;li&gt;Name: "User"&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;li&gt;2nd element&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;expression: {($_.group | measure-object).count}&lt;br /&gt;&lt;li&gt;Name: "Count"&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;li&gt;3rd element&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;expression: {($_.group | measure-object -property RoundedSize -sum).sum}&lt;br /&gt;&lt;li&gt;Name: "MB"&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;The value of "Name" key of each Hashobject is used as a header for the output while the values of "expression" evaluate piped input data object(in this case, System.Management.Automation.Commands.GroupInfo object) and spits out the output on the console.&lt;br /&gt;In /\/\o\/\/'s case,&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;User                                    Count                                            MB&lt;br&gt;----                                    -----                                            --&lt;br&gt;Usr001                                    &lt;span style="color: maroon;"&gt;141&lt;/span&gt;                                        &lt;span style="color: maroon;"&gt;998&lt;/span&gt;,&lt;span style="color: maroon;"&gt;52&lt;/span&gt;&lt;br&gt;Usr002                                    &lt;span style="color: maroon;"&gt;547&lt;/span&gt;                                       &lt;span style="color: maroon;"&gt;3746&lt;/span&gt;,&lt;span style="color: maroon;"&gt;62&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can see that "User", "Count", and "MB" as headers and the results are simply calculated values from the piped input data.&lt;br /&gt;&lt;br /&gt;BTW, to save typing, you don't have to go with something like &lt;span style="font-weight:bold;"&gt;expression={$_.filename}; name="Filename"&lt;/span&gt;(probably for better readability?) since there is no real meaning to name your keys("expression" &amp; "name") that long...  For me being such a lazy typist... i was satisfied with the following...&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;br&gt;$Userfiles&amp;nbsp;|&amp;nbsp;group&amp;nbsp;Username&amp;nbsp;|&amp;nbsp;select&amp;nbsp;@{e={$_.Name};N=&lt;span style="color: maroon;"&gt;"User"&lt;/span&gt;}, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@{e={($_.group&amp;nbsp;|&amp;nbsp;measure-&lt;span style="color: blue;"&gt;object&lt;/span&gt;).count};N=&lt;span style="color: maroon;"&gt;"Count"&lt;/span&gt;}, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@{e={($_.group&amp;nbsp;|&amp;nbsp;measure-&lt;span style="color: blue;"&gt;object&lt;/span&gt;&amp;nbsp;-property&amp;nbsp;RoundedSize&amp;nbsp;-sum).sum};N=&lt;span style="color: maroon;"&gt;"MB"&lt;/span&gt;}&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Anyways, it was a fun fun script there /\/\o\/\/~~~&lt;br /&gt;&lt;br /&gt;Tags : &lt;/span&gt;&lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113687501967336446?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://mow001.blogspot.com/2006/01/report-mp3-count-and-size-by-user-from.html' title='/\/\o\/\/ on MSH (Monad): Report MP3 count and size by User from MSH'/><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113687501967336446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113687501967336446' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113687501967336446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113687501967336446'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/01/o-on-msh-monad-report-mp3-count-and.html' title='/\/\o\/\/ on MSH (Monad): Report MP3 count and size by User from MSH'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113677162519864000</id><published>2006-01-08T20:30:00.000-05:00</published><updated>2006-01-08T21:24:38.750-05:00</updated><title type='text'>[FUN] (Poor Man's) SONY Rootkit Revealer</title><content type='html'>I was listening to &lt;a href="http://www.grc.com/securitynow.htm"&gt;"Security Now" &lt;/a&gt; episode #12 (&lt;a href="http://www.grc.com/sn/SN-012.htm"&gt;Transcript for that episode and links to the podcast on the top of the page&lt;/a&gt;) and SONY's Rootkit can be revealed by creating any file that starts with "$sys".&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NOTE:&lt;/b&gt;To those who still haven't heard of the term &lt;i&gt;Rootkit&lt;/i&gt; it's advised that you either "google" about it or check out &lt;a href="http://www.grc.com/sn/SN-009.htm"&gt;Security Now Episode #9&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Well.. I was sitting down and see if i had rootkit or not...&lt;br /&gt;Ah.. all this does is just simply creating a file that starts with &lt;span style="font-weight:bold;"&gt;$sys$&lt;/span&gt;($sys$test.txt) and check if exists after creating it(and deletes later on).  There is no fancy stuff done here...&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;&lt;font color='Green'&gt;# author: dance2die&lt;/font&gt;&lt;br /&gt;&lt;font color='Green'&gt;# title: &lt;b&gt;Ghetto SONY Rootkit Revealer~&lt;/b&gt; :)&lt;/font&gt;&lt;br /&gt;&lt;font color='Green'&gt;# date: 01/08/2005 @ 20:05&lt;/font&gt;&lt;br /&gt;&lt;font color='Green'&gt;# comment: LOL, this is quite funny...&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color='Blue'&gt;function&lt;/font&gt; RevealSONYRootkit {&lt;br /&gt;    &lt;font color='Green'&gt;# create a file(in a current dir)&lt;/font&gt;&lt;br /&gt;    &lt;font color='Green'&gt;# that starts with "$sys$" which is what SONY used to hide their files.&lt;/font&gt;&lt;br /&gt;    $private:testFile = &lt;font color='Maroon'&gt;".\`$sys`$test.txt"&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;    trap [System.IO.FileNotFoundException] {&lt;br /&gt;        &lt;font color='Green'&gt;# well something happend so i am guessing that the a rootkit is on the machine..&lt;/font&gt;&lt;br /&gt;        Write-Host -foregroundColor &lt;font color='Maroon'&gt;"red"&lt;/font&gt; -backgroundcolor &lt;font color='Maroon'&gt;"white"&lt;/font&gt; &lt;font color='Maroon'&gt;"You might have SONY rootkit installed... I am chickening out..."&lt;/font&gt;&lt;br /&gt;        &lt;font color='Blue'&gt;if&lt;/font&gt; ([System.IO.File]::Exists($private:TestFile)) remove-item $private:testFile&lt;br /&gt;        &lt;font color='Blue'&gt;break&lt;/font&gt;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;font color='Blue'&gt;If&lt;/font&gt; (![System.IO.File]::Exists($private:testFile)) {&lt;br /&gt;        &lt;font color='Green'&gt;# i am not using [void] here since new-item will display the file created on console... to make sure that people get to see the result&lt;/font&gt;&lt;br /&gt;        new-item -type file $private:testFile&lt;br /&gt;    } &lt;font color='Blue'&gt;else&lt;/font&gt; {&lt;br /&gt;        Write-Host -foregroundColor &lt;font color='Maroon'&gt;"green"&lt;/font&gt;  -backgroundcolor &lt;font color='Maroon'&gt;"white"&lt;/font&gt; &lt;font color='Maroon'&gt;"Your system is clean..."&lt;/font&gt;&lt;br /&gt;        &lt;font color='Green'&gt;# i don't usually like to have multiple exit points in a function but wth...&lt;/font&gt;&lt;br /&gt;        &lt;font color='Blue'&gt;return&lt;/font&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;font color='Blue'&gt;if&lt;/font&gt; ([System.IO.File]::Exists($private:testFile)) {&lt;br /&gt;        Write-Host -foregroundColor &lt;font color='Maroon'&gt;"green"&lt;/font&gt;  -backgroundcolor &lt;font color='Maroon'&gt;"white"&lt;/font&gt; &lt;font color='Maroon'&gt;"Your system is clean..."&lt;/font&gt;&lt;br /&gt;    } &lt;font color='Blue'&gt;else&lt;/font&gt; {&lt;br /&gt;        Write-Host -foregroundColor &lt;font color='Maroon'&gt;"red"&lt;/font&gt; -backgroundcolor &lt;font color='Maroon'&gt;"white"&lt;/font&gt; &lt;font color='Maroon'&gt;"FATAL:You have a SONY Rootkit installed!!!`nReinstall your Windows!!!"&lt;/font&gt;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    remove-item $private:testFile&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;If you don't have SONY Rootkit then you will see:&lt;br /&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/blogger/Clean.gif" alt="Image hosted by Photobucket.com"&gt;&lt;br /&gt;&lt;br /&gt;Or.. if you happened to be one of those unlucky ones...:&lt;br /&gt;&lt;img src="http://img.photobucket.com/albums/v138/dance2die/blogger/Infected.gif" alt="Image hosted by Photobucket.com"&gt;&lt;br /&gt;&lt;br /&gt;Wouldn't it be great if someone could modify this to run this function over network? :)&lt;br /&gt;Ah.. an instance of "System.Management.Automation.MshCredential" class argument can come in handy..&lt;br /&gt;&lt;br /&gt;Well.. Run it at your own risk.. :)&lt;br /&gt;&lt;br /&gt;Tags: &lt;a href="http://technorati.com/tag/fun" rel="tag"&gt;fun&lt;/a&gt; &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt; &lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt;  &lt;a href="http://technorati.com/tag/security" rel="tag"&gt;security&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113677162519864000?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113677162519864000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113677162519864000' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113677162519864000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113677162519864000'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/01/fun-poor-mans-sony-rootkit-revealer.html' title='[FUN] (Poor Man&apos;s) SONY Rootkit Revealer'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113662526770357961</id><published>2006-01-07T03:59:00.000-05:00</published><updated>2006-01-07T05:09:49.860-05:00</updated><title type='text'>[TechNet] Do Scripters Dream of Magenta-Colored Text?</title><content type='html'>I was going over one of the highlighted &lt;a href="http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx"&gt;Microsoft TechNet MSH Scripting&lt;/a&gt;  article&lt;br /&gt;&lt;a href="http://www.microsoft.com/technet/scriptcenter/topics/msh/output.mspx"&gt;Do Scripters Dream of Magenta-Colored Text?&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The highlighted article talks about how to "Display Output in Color Using the Microsoft Shell".  The gist of the whole discussion was about "-foreground" flag of "write-host" cmdlet(pronounced as Commandlet) which would let the scripter to decide which color(any of System.ConsoleColor retrievable through "MSH&gt;$host.ui.rawui.foregroundcolor | gm -static")&lt;br /&gt;&lt;br /&gt;The script seems to be from the guys who has written many VBScript tech scripts because the author has used WMI Class called "Win32_Process" which holds current process information of local or remote machine.  I had a feeling that the author had no idea about "get-process".&lt;br /&gt;&lt;br /&gt;Anyways, the following is the Scripting Guy's solution for displaying current process information in "Magenta" color.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;$strComputer = &lt;span style=' color: Maroon;'&gt;"."&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;$colItems = get-wmiobject -class &lt;span style=' color: Maroon;'&gt;"Win32_Process"&lt;/span&gt; -namespace &lt;span style=' color: Maroon;'&gt;"root\CIMV2"&lt;/span&gt; ` &lt;br /&gt;-computername $strComputer | write-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;foreach&lt;/span&gt; ($objItem &lt;span style=' color: Blue;'&gt;in&lt;/span&gt; $colItems) { &lt;br /&gt;      write-host $objItem.Name, $objItem.WorkingSetSize -foregroundcolor &lt;span style=' color: Maroon;'&gt;"magenta"&lt;/span&gt; &lt;br /&gt;}&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;The following is the shorter version using "get-process"&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;MSH&amp;gt;get-process | &lt;span style=' color: Blue;'&gt;foreach&lt;/span&gt; { write-host $_.name, $_.WorkingSet -foregroundcolor &lt;span style=' color: Maroon;'&gt;"magenta"&lt;/span&gt; }&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;Woah, wasn't that much shorter and easier to write and read?&lt;br /&gt;Anyways, one draw back of the latter approach is that it does not display "System Idle Process"... But not like anyone cares about that none process... :)&lt;br /&gt;&lt;br /&gt;Tags:&lt;a href="http://technorati.com/tag/msh" rel="tag"&gt;msh&lt;/a&gt; &lt;a href="http://technorati.com/tag/Monad" rel="tag"&gt;Monad&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113662526770357961?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113662526770357961/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113662526770357961' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113662526770357961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113662526770357961'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2006/01/technet-do-scripters-dream-of-magenta.html' title='[TechNet] Do Scripters Dream of Magenta-Colored Text?'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113433495237314041</id><published>2005-12-11T15:35:00.000-05:00</published><updated>2005-12-11T16:05:46.053-05:00</updated><title type='text'>Strange "Get-Member" behavior(Title borrowed from Mow's blog)</title><content type='html'>Ok, it was weird that whenever I was trying to see if a returned value if of a type array or a scalar.&lt;br /&gt;&lt;br /&gt;I have been frusted to see foreach or .length property of output to see if the returned value is an array or not.&lt;br /&gt;&lt;br /&gt;But I don't think I would have to worry about it no more.&lt;br /&gt;&lt;br /&gt;Strangely enough,&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;MSH&gt;((get-help get-childitem)."#comment") | gm&lt;/blockquote&gt;&lt;br /&gt;would result in displaying type information for type of stored information in the result array object instead of displaying the type of actual array.&lt;br /&gt;&lt;br /&gt;But apparently there was at least one another person who was having the similiar problem.  &lt;br /&gt;&lt;br /&gt;&lt;a href="http://mow001.blogspot.com"&gt;Mow&lt;/a&gt; gave me the answer on Usenet &lt;a href="http://groups.google.com/group/microsoft.public.windows.server.scripting/browse_frm/thread/1d182dff193a7a7c/d748c8e0fc06088d#d748c8e0fc06088d"&gt;newsgroup post&lt;/a&gt; and &lt;br /&gt;Here is the answer he posted.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;MSH&gt;,((get-help get-childitem)."#comment") | gm &lt;br /&gt;&lt;br /&gt;     TypeName: System.Management.Automation.MshObject[] &lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Note that, only difference here was that "," is used to before piping the output to "gm".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more extensive coverage and answer for this behavior, I recommend &lt;br /&gt;&lt;a href="http://mow001.blogspot.com/2005/11/create-system-variable-from-msh-part2.html"&gt;/\/\o\/\/ on MSH (Monad): Create System Variable From MSH (Part2)&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you read through his blog, there is another way to retrieve type information of the array.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;gm -input ((get-help get-childitem)."#comment")&lt;/blockquote&gt;&lt;br /&gt;Apparently this latter solution works as well.&lt;br /&gt;But why?&lt;br /&gt;&lt;br /&gt;Thanks &lt;a href="http://mow001.blogspot.com"&gt;/\/\o\/\/&lt;/a&gt; for another tip there :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113433495237314041?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113433495237314041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113433495237314041' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113433495237314041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113433495237314041'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/12/strange-get-member-behaviortitle.html' title='Strange &quot;Get-Member&quot; behavior(Title borrowed from Mow&apos;s blog)'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113373242799809209</id><published>2005-12-04T15:57:00.000-05:00</published><updated>2005-12-04T16:40:28.206-05:00</updated><title type='text'>Calling Win32 API functions through MSH</title><content type='html'>I have always been wondering if there is a native(in terms of MSH context) way to call Win32 API functions inside MSH. There isn't a built-in way to call Win32 API functions directly.&lt;br /&gt;&lt;br /&gt;Oh, don't be disappointed, though. There is a work-around; Dynamic in-memory compilation of C#/VB.net code does the trick.&lt;br /&gt;&lt;br /&gt;Well, another day and another day at UseNet newsgroup, I have found the answer.&lt;br /&gt;Solutions were provided by &lt;a href="http://mow001.blogspot.com/"&gt;/\/\o\/\/&lt;/a&gt;(with VB.net solution) and &lt;a href="http://groups.google.com/group/microsoft.public.windows.server.scripting/browse_frm/thread/bc545204505bb3a8/c8a9a064a32aa926#c8a9a064a32aa926"&gt;Jeffery Snover&lt;/a&gt; for in-memory compilation of C# code snippet.&lt;br /&gt;&lt;br /&gt;My next project will be creating a utility MSH function to ease the pain of declaring and using Win32 API functions&lt;br /&gt;&lt;br /&gt;e.g.) new-win32_function declaration [[-ns namespace] [-cn classname]]&lt;br /&gt;new-win32_function "public static extern int puts(string c)" -ns TestNs -cl TestApp&lt;br /&gt;Would let me use "puts" function like the following&lt;br /&gt;MSH&gt; [TestNs.TestApp]::puts("test")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://groups.google.com/group/microsoft.public.windows.server.scripting/browse_frm/thread/bc545204505bb3a8/c8a9a064a32aa926#c8a9a064a32aa926"&gt;/\/\o\/\/'s VB.NET solution&lt;/a&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;$provider = new-&lt;span style="color:blue;"&gt;object&lt;/span&gt; Microsoft.VisualBasic.VBCodeProvider&lt;br /&gt;$params = new-&lt;span style="color:blue;"&gt;object&lt;/span&gt; System.CodeDom.Compiler.CompilerParameters&lt;br /&gt;$params.GenerateInMemory = $True&lt;br /&gt;$refs = &lt;span style="color:maroon;"&gt;"System.dll"&lt;/span&gt;,&lt;span style="color:maroon;"&gt;"Microsoft.VisualBasic.dll"&lt;/span&gt;&lt;br /&gt;$params.ReferencedAssemblies.AddRange($refs)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# VB.NET EXAMPLE &lt;/span&gt;&lt;br /&gt;$txtCode = @'&lt;br /&gt;Class mow&lt;br /&gt;   Declare Auto &lt;span style="color:blue;"&gt;Function&lt;/span&gt; MyMessageBox Lib “user32.dll” Alias _&lt;br /&gt;   “MessageBox” (ByVal hWnd as Integer, ByVal msg as &lt;span style="color:blue;"&gt;String&lt;/span&gt;, _&lt;br /&gt;   ByVal Caption as &lt;span style="color:blue;"&gt;String&lt;/span&gt;, ByVal Tpe as Integer) As Integer&lt;br /&gt;Sub Main()&lt;br /&gt;     MyMessageBox(&lt;span style="color:maroon;"&gt;0&lt;/span&gt;, &lt;span style="color:maroon;"&gt;"Hello World !!!"&lt;/span&gt;, &lt;span style="color:maroon;"&gt;"Project  Title"&lt;/span&gt;, &lt;span style="color:maroon;"&gt;0&lt;/span&gt;)&lt;br /&gt;End Sub&lt;br /&gt;end class&lt;br /&gt;'@&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$results = $provider.CompileAssemblyFromSource($params, $txtCode)&lt;br /&gt;$mAssembly = $results.CompiledAssembly&lt;br /&gt;$i = $mAssembly.CreateInstance(&lt;span style="color:maroon;"&gt;"mow"&lt;/span&gt;)&lt;br /&gt;$r = $i.main()&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;and here is the C# solution(Modified a bit to fix syntax error)&lt;br /&gt;&lt;a href="http://groups.google.com/group/microsoft.public.windows.server.scripting/browse_frm/thread/bc545204505bb3a8/c8a9a064a32aa926#c8a9a064a32aa926"&gt;Jeffery's C# solution&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color:green;"&gt;##################################################### &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;#  This is a general purpose routine that I put into a file called &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;#   LibraryCodeGen.msh and then dot-source when I need it. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;##################################################### &lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;function&lt;/span&gt; Compile-Csharp ([&lt;span style="color:blue;"&gt;string&lt;/span&gt;] $code, $FrameworkVersion=&lt;span style="color:maroon;"&gt;"v2.0.50727"&lt;/span&gt;,&lt;br /&gt;[Array]$References)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color:green;"&gt;# &lt;/span&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;# Get an instance of the CSharp code provider &lt;/span&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;# &lt;/span&gt;&lt;br /&gt;    $cp = new-&lt;span style="color:blue;"&gt;object&lt;/span&gt; Microsoft.CSharp.CSharpCodeProvider&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;# &lt;/span&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;# Build up a compiler params object... &lt;/span&gt;&lt;br /&gt;    &lt;span style="color:green;"&gt;# &lt;/span&gt;&lt;br /&gt;    &lt;span style="color:maroon;"&gt;"${framework}\System.Data.dll,${framework}\System.dll,${framework}\system.xm&amp;shy;l.dll"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    $framework = Combine-Path $env:windir &lt;span style="color:maroon;"&gt;"Microsoft.NET\Framework\$FrameWorkVersion"&lt;/span&gt;&lt;br /&gt;    $refs = new-&lt;span style="color:blue;"&gt;object&lt;/span&gt; Collections.ArrayList&lt;br /&gt;    $refs.AddRange( @(&lt;span style="color:maroon;"&gt;"${framework}\System.dll"&lt;/span&gt;,&lt;br /&gt;        &lt;span style="color:maroon;"&gt;"${mshhome}\System.Management.Automation.dll"&lt;/span&gt;,&lt;br /&gt;        &lt;span style="color:maroon;"&gt;"${mshhome}\System.Management.Automation.ConsoleHost.dll"&lt;/span&gt;,&lt;br /&gt;        &lt;span style="color:maroon;"&gt;"${framework}\system.windows.forms.dll"&lt;/span&gt;,&lt;br /&gt;        &lt;span style="color:maroon;"&gt;"${framework}\System.data.dll"&lt;/span&gt;,&lt;br /&gt;        &lt;span style="color:maroon;"&gt;"${framework}\System.Drawing.dll"&lt;/span&gt;,&lt;br /&gt;        &lt;span style="color:maroon;"&gt;"${framework}\System.Xml.dll"&lt;/span&gt;))&lt;br /&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; ($references.Count -ge &lt;span style="color:maroon;"&gt;1&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        $refs.AddRange($References)&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    $cpar = New-&lt;span style="color:blue;"&gt;Object&lt;/span&gt; System.CodeDom.Compiler.CompilerParameters&lt;br /&gt;    $cpar.GenerateInMemory = $&lt;span style="color:maroon;"&gt;true&lt;/span&gt;&lt;br /&gt;    $cpar.GenerateExecutable = $&lt;span style="color:maroon;"&gt;false&lt;/span&gt;&lt;br /&gt;    $cpar.OutputAssembly = &lt;span style="color:maroon;"&gt;"custom"&lt;/span&gt;&lt;br /&gt;    $cpar.ReferencedAssemblies.AddRange($refs)&lt;br /&gt;    $cr = $cp.CompileAssemblyFromSource($cpar, $code)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;if&lt;/span&gt; ( $cr.Errors.Count)&lt;br /&gt;    {&lt;br /&gt;        $codeLines = $code.Split(&lt;span style="color:maroon;"&gt;"`n"&lt;/span&gt;);&lt;br /&gt;        &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; ($ce &lt;span style="color:blue;"&gt;in&lt;/span&gt; $cr.Errors)&lt;br /&gt;        {&lt;br /&gt;            write-host &lt;span style="color:maroon;"&gt;"Error: $($codeLines[$($ce.Line - 1)])"&lt;/span&gt;&lt;br /&gt;            $ce out-default&lt;br /&gt;        }&lt;br /&gt;        Throw &lt;span style="color:maroon;"&gt;"INVALID DATA: Errors encountered while compiling code"&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;######################################################### &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;#  Here I leverage one of my favorite features (here-strings) to define &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# the C# code I want to run.  Remember - if you use single quotes - the &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# string is taken literally but if you use double-quotes, we'll do variable &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# expansion.  This can be VERY useful. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;######################################################### &lt;/span&gt;&lt;br /&gt;$code = '&lt;br /&gt;using System;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;namespace test&lt;br /&gt;{&lt;br /&gt;    public class Testclass&lt;br /&gt;    {&lt;br /&gt;        [DllImport(&lt;span style="color:maroon;"&gt;"msvcrt.dll"&lt;/span&gt;)]&lt;br /&gt;        public static extern &lt;span style="color:blue;"&gt;int&lt;/span&gt; puts(&lt;span style="color:blue;"&gt;string&lt;/span&gt; c);&lt;br /&gt;        [DllImport(&lt;span style="color:maroon;"&gt;"msvcrt.dll"&lt;/span&gt;)]&lt;br /&gt;        internal static extern &lt;span style="color:blue;"&gt;int&lt;/span&gt; _flushall();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        public static &lt;span style="color:blue;"&gt;void&lt;/span&gt; Run(&lt;span style="color:blue;"&gt;string&lt;/span&gt; message)&lt;br /&gt;        {&lt;br /&gt;            puts(message);&lt;br /&gt;            _flushall();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;'&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;######################################################## &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;# So now we compile the code and use .NET object access to run it. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;######################################################## &lt;/span&gt;&lt;br /&gt;compile-CSharp $code&lt;br /&gt;[Test.TestClass]::Run(&lt;span style="color:maroon;"&gt;"Monad ROCKS!"&lt;/span&gt;) &lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Has anyone ever noticed that "Solution" sounds better than simply referring it as "answer"?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113373242799809209?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113373242799809209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113373242799809209' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113373242799809209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113373242799809209'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/12/calling-win32-api-functions-through.html' title='Calling Win32 API functions through MSH'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113332824166694840</id><published>2005-11-30T00:21:00.000-05:00</published><updated>2005-11-30T00:25:26.786-05:00</updated><title type='text'>PDC05 Hands-On Lab on Creating Monad Providers</title><content type='html'>what is "PDC05 Hands-On Lab on &lt;i&gt;Creating Monad Providers&lt;/i&gt;" you ask?  It is one of the Word doc that comes with MSH Beta 2 documentation.&lt;br /&gt;&lt;br /&gt;Hmm.. I must say that it is really darn good of a tutorial for dealing with creating a new provider for MSH...&lt;br&gt; The lab basically deals with creating a new MSH provider for accessing MDB file(Microsoft Access DB) as if it were a local filesystem.&lt;br&gt; &lt;br&gt; &lt;br&gt; It is possible to implement the provider to handle all the basic MSH core commands(help page available through "get-help about_core_commands" on the MSH prompt), such as "get-childitem"(aliased as "ls" or "dir"), "get-content"(aliased as "gc"), "set-localtion"(aliased as "cd"), and etc...&lt;br&gt; &lt;br&gt; &lt;br&gt; Some of the implementations for features like deleting(implementing "RemoveItem" for "NavigationCmdletProvider"), adding("NavigationCmdletProvider.NewItem") and updating Access DB data are intentionally left out for people to try to implement.&lt;br&gt; &lt;br&gt;&lt;br&gt; Overall, spending 2~3 hours on this lab was surely worth it.&lt;br&gt; &lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113332824166694840?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113332824166694840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113332824166694840' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113332824166694840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113332824166694840'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/pdc05-hands-on-lab-on-creating-monad.html' title='PDC05 Hands-On Lab on &lt;i&gt;Creating Monad Providers&lt;/i&gt;'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113183571640422792</id><published>2005-11-12T17:43:00.000-05:00</published><updated>2005-11-12T17:48:36.406-05:00</updated><title type='text'>[MSH] Disposing COM object.</title><content type='html'>I had a problem with this "Speak" function I had posted on 11/08/2005, &lt;a href="http://monadblog.blogspot.com/2005/11/o-on-msh-monad-msh-start.html"&gt;Here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The problem was that, "Speak" function did not dispose the excel object create so even after MSH was exited, the COM object would still be alive and could be seen in Task Manager.  So i hit the Newsgroup and have found the &lt;a href="http://groups.google.com/group/microsoft.public.windows.server.scripting/browse_thread/thread/54594c91758c6cad/228ff94bb78e8ced?lnk=raot#228ff94bb78e8ced"&gt;answer&lt;/a&gt;(Thanks to both "Jouko Kynsijärvi" and "Keith Hill") on how to dipose that darn COM object.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;Keith Hill &lt;br /&gt; Nov 12, 12:55 pm   show options &lt;br /&gt;&lt;br /&gt;Newsgroups: microsoft.public.windows.server.scripting &lt;br /&gt;From: "Keith Hill" &lt;r_keith_h...@no.spam.thank.u.hotmail.com&gt; - Find messages by this author  &lt;br /&gt;Date: Sat, 12 Nov 2005 10:55:39 -0700 &lt;br /&gt;Local: Sat, Nov 12 2005 12:55 pm  &lt;br /&gt;Subject: Re: [MSH] How to dispose a COM object &lt;br /&gt;Reply | Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"Jouko Kynsijärvi" &lt;jouko.kynsija...@nospam.nospam&gt; wrote in message &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;news:%23pf9pW65FHA.2040@TK2MSFTNGP14.phx.gbl... &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&gt; You can release the COM object by using Marshal.ReleaseComObject(): &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Keep in mind that if you marshal a COM object back and forth between &lt;br /&gt;different COM servers and MSH, the ref count on the RCW can get bumped up &lt;br /&gt;past 1.  That means that if you really, really want to get rid of the COM &lt;br /&gt;object you typically do this: &lt;br /&gt;&lt;br /&gt;while &lt;br /&gt;([System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComOb­ject]$excel) &lt;br /&gt; -gt 0) {} &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Essentially ReleaseComObject returns the new ref count and you want to &lt;br /&gt;continue calling it until the ref count reaches 0.  At least this was the &lt;br /&gt;way it worked in .NET 1.1.   And indeed the .NET 2.0 docs say: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      Note &lt;br /&gt;      To ensure that the runtime callable wrapper and the original COM &lt;br /&gt;object are released, construct a loop from which you call this method until &lt;br /&gt;the returned reference count reaches zero. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Yeah I've been bit by this issue before. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- &lt;br /&gt;Keith &lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113183571640422792?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113183571640422792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113183571640422792' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113183571640422792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113183571640422792'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/msh-disposing-com-object.html' title='[MSH] Disposing COM object.'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113183313582851652</id><published>2005-11-12T16:52:00.000-05:00</published><updated>2005-11-12T17:09:39.806-05:00</updated><title type='text'>[Non-MSH] Stupid function practice</title><content type='html'>As I was browsing &lt;a href="http://msdn2.microsoft.com"&gt;MSDN2&lt;/a&gt; website to see if there is any useful classes and function I could use to maintain SQL 2000 server or my comp.&lt;br /&gt;&lt;br /&gt;I have come across a namespace &lt;a href="http://msdn2.microsoft.com/en-us/library/ms127097(en-us,VS.80).aspx"&gt;Microsoft.SqlServer.Server&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Ah, great, there should be a lot of fun stuff in it.&lt;br /&gt;So I thought.&lt;br /&gt;&lt;br /&gt;But i ran into this rather interestingly named function &lt;a href="http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.server.sqlpipe.executeandsend"&gt;ExecuteAndSend&lt;/a&gt; of &lt;a href="http://msdn2.microsoft.com/en-us/library/ms127312(en-US,VS.80).aspx"&gt;SqlPipe&lt;/a&gt; class.&lt;br /&gt;&lt;br /&gt;AFAIK, a function should do ONE thing and ONE thing only, WELL.&lt;br /&gt;Is it that hard to write a code like&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;SqlContext.Pipe.Execute(); &lt;br /&gt;SqlContext.Pipe.Send(); &lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Green;'&gt;// Instead of &lt;/span&gt; &lt;br /&gt;SqlContext.Pipe.ExecuteAndSend();&lt;/pre&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;BTW, this "ExecuteAndSend" reminds of "SendAndExit"(i think i saw something like this from Outlook) and "SaveAndExit" functionality in Crystal Reports Formula Editor&lt;br /&gt;&lt;br /&gt;I tend to despise such a coding practice...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113183313582851652?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113183313582851652/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113183313582851652' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113183313582851652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113183313582851652'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/non-msh-stupid-function-practice.html' title='[Non-MSH] Stupid function practice'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113176019260147503</id><published>2005-11-11T20:39:00.000-05:00</published><updated>2005-11-11T20:49:52.616-05:00</updated><title type='text'>Show Desktop in MSH way</title><content type='html'>Ok, I have modified "/\/\o\/\/" yet further.&lt;br /&gt;I have lost that darn "show desktop" button and it was a pain in the ass to get it back on to my "quick launch".  Ah, and yeah, when i program, I need to title windows either horizontally or vertically so that i could compare two code side by side.&lt;br /&gt;&lt;br /&gt;But oh well, to tile windows, i had to select windows one by one pressing controls and then title'em all...  So i created another MSH script that do just what I mentioned.&lt;br /&gt;&lt;br /&gt;There are many options that Shell.Application offers and I will be extending this script to support all the functionalities that Shell.Application offers...&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style=' color: Green;'&gt;&lt;br /&gt;# ShellUtil.msh&lt;br /&gt;# author: dance2die&lt;br /&gt;# original code author: /\/\o\/\/# date: 11/11/2005 @ 08:51PM&lt;br /&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;[System.Reflection.Assembly]::LoadWithPartialName(&lt;span style=' color: Maroon;'&gt;"System.Drawing"&lt;/span&gt;) &lt;br /&gt;[System.Reflection.Assembly]::LoadWithPartialName(&lt;span style=' color: Maroon;'&gt;"System.windows.forms"&lt;/span&gt;) &lt;br /&gt;&lt;br /&gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; ShellUtil { &lt;br /&gt;&lt;br /&gt;    $shell = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; -com shell.application &lt;br /&gt;&lt;br /&gt;    $form = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.form &lt;br /&gt;    $cm = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.ContextMenu         &lt;br /&gt;    $mi = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.MenuItem         &lt;br /&gt;    $ni = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.NotifyIcon         &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Display "Show Desktop" menu&lt;/span&gt; &lt;br /&gt;    $miToggle = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.MenuItem &lt;br /&gt;    $miToggle.Index = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt; &lt;br /&gt;    $miToggle.Text = &lt;span style=' color: Maroon;'&gt;"&amp;amp;Show Desktop"&lt;/span&gt; &lt;br /&gt;     &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Display "Minimize All" menu&lt;/span&gt; &lt;br /&gt;    $miMinAll = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.MenuItem &lt;br /&gt;    $miMinAll.Text = &lt;span style=' color: Maroon;'&gt;"&amp;amp;Minimize All Windows"&lt;/span&gt; &lt;br /&gt;    $miMinAll.Index = &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt; &lt;br /&gt;     &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Display "Undo Minimize All" menu&lt;/span&gt; &lt;br /&gt;    $miUndoMinAll = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.MenuItem &lt;br /&gt;    $miUndoMinAll.Index = &lt;span style=' color: Maroon;'&gt;2&lt;/span&gt; &lt;br /&gt;    $miUndoMinAll.Text = &lt;span style=' color: Maroon;'&gt;"&amp;amp;Undo Minimize All Windows"&lt;/span&gt;; &lt;br /&gt;     &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Display "Tray Properties" menu&lt;/span&gt; &lt;br /&gt;    $miTrayProps = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.MenuItem &lt;br /&gt;    $miTrayProps.Index = &lt;span style=' color: Maroon;'&gt;3&lt;/span&gt; &lt;br /&gt;    $miTrayProps.Text = &lt;span style=' color: Maroon;'&gt;"&amp;amp;Tray Properties..."&lt;/span&gt; &lt;br /&gt;     &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Display "Cascade Windows" menu&lt;/span&gt; &lt;br /&gt;    $miCascade = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.MenuItem &lt;br /&gt;    $miCascade.Index = &lt;span style=' color: Maroon;'&gt;4&lt;/span&gt; &lt;br /&gt;    $miCascade.Text = &lt;span style=' color: Maroon;'&gt;"&amp;amp;Cascade Windows"&lt;/span&gt; &lt;br /&gt;     &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Display "Tile Horizontally" menu&lt;/span&gt; &lt;br /&gt;    $miTileH = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.MenuItem &lt;br /&gt;    $miTileH.Index = &lt;span style=' color: Maroon;'&gt;5&lt;/span&gt; &lt;br /&gt;    $miTileH.Text = &lt;span style=' color: Maroon;'&gt;"Tile Windows &amp;amp;Horizontally"&lt;/span&gt; &lt;br /&gt;     &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Display "Tile Vertically" menu&lt;/span&gt; &lt;br /&gt;    $miTileV = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Windows.Forms.MenuItem &lt;br /&gt;    $miTileV.Index = &lt;span style=' color: Maroon;'&gt;6&lt;/span&gt; &lt;br /&gt;    $miTileV.Text = &lt;span style=' color: Maroon;'&gt;"Tile Windows &amp;amp;Vertically"&lt;/span&gt; &lt;br /&gt;     &lt;br /&gt;    &lt;span style=' color: Green;'&gt;# Display "Exit" menu&lt;/span&gt; &lt;br /&gt;    $miExit = new-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.windows.Forms.MenuItem &lt;br /&gt;    $miExit.Index = &lt;span style=' color: Maroon;'&gt;10&lt;/span&gt; &lt;br /&gt;    $miExit.Text = &lt;span style=' color: Maroon;'&gt;"E&amp;amp;xit"&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    $form.contextMenu = $cm         &lt;br /&gt;    $form.contextMenu.MenuItems.Add($miToggle) &lt;br /&gt;    $form.contextMenu.MenuItems.Add($miMinAll) &lt;br /&gt;    $form.contextMenu.MenuItems.Add($miUndoMinAll) &lt;br /&gt;    $form.contextMenu.MenuItems.Add($miTrayProps) &lt;br /&gt;    $form.contextMenu.MenuItems.Add($miCascade) &lt;br /&gt;    $form.contextMenu.MenuItems.Add($miTileH) &lt;br /&gt;    $form.contextMenu.MenuItems.Add($miTileV) &lt;br /&gt;    $form.contextMenu.MenuItems.Add($miExit) &lt;br /&gt;     &lt;br /&gt;     &lt;br /&gt;    $form.ShowInTaskbar = $False         &lt;br /&gt;    $form.WindowState = &lt;span style=' color: Maroon;'&gt;"minimized"&lt;/span&gt;      &lt;br /&gt;    $form.add_Closing({ $form.ShowInTaskBar = $False }) &lt;br /&gt;&lt;br /&gt;    $ni = $ni         &lt;br /&gt;    $ni.Icon = New-&lt;span style=' color: Blue;'&gt;object&lt;/span&gt; System.Drawing.Icon(&lt;span style=' color: Maroon;'&gt;"c:\programming\msh\icons\test.ico"&lt;/span&gt;) &lt;br /&gt;    $NI.ContextMenu = $cm         &lt;br /&gt;    $NI.Text += &lt;span style=' color: Maroon;'&gt;"Shell Utility"&lt;/span&gt;; &lt;br /&gt;&lt;br /&gt;    $tipTitle = &lt;span style=' color: Maroon;'&gt;"Bah"&lt;/span&gt; &lt;br /&gt;    $tipText = &lt;span style=' color: Maroon;'&gt;"Bah"&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;    $miToggle.add_Click({  &lt;br /&gt;        $shell.ToggleDesktop() &lt;br /&gt;        $tipTitle = &lt;span style=' color: Maroon;'&gt;"Show Desktop"&lt;/span&gt; &lt;br /&gt;        $tipText = &lt;span style=' color: Maroon;'&gt;"Toggle Desktop..."&lt;/span&gt; &lt;br /&gt;    }) &lt;br /&gt;    $miMinAll.add_Click({ &lt;br /&gt;        $shell.MinimizeAll() &lt;br /&gt;        $tipTitle = &lt;span style=' color: Maroon;'&gt;"Minimize All..."&lt;/span&gt; &lt;br /&gt;        $tipText = &lt;span style=' color: Maroon;'&gt;"Minimize All windows..."&lt;/span&gt; &lt;br /&gt;    }) &lt;br /&gt;    $miUndoMinAll.add_Click({  &lt;br /&gt;        $shell.UndoMinimizeAll()  &lt;br /&gt;        $tipTitle = &lt;span style=' color: Maroon;'&gt;"Undo minimize all"&lt;/span&gt; &lt;br /&gt;        $tipText = &lt;span style=' color: Maroon;'&gt;"Undo minimize all"&lt;/span&gt; &lt;br /&gt;    }) &lt;br /&gt;    $miTrayProps.add_Click({  &lt;br /&gt;        $shell.TrayProperties() &lt;br /&gt;        $tipTitle = &lt;span style=' color: Maroon;'&gt;"Display Tray Properties"&lt;/span&gt; &lt;br /&gt;        $tipText = &lt;span style=' color: Maroon;'&gt;"Modify system tray properties..."&lt;/span&gt; &lt;br /&gt;    }) &lt;br /&gt;    $miCascade.add_Click({ &lt;br /&gt;        $shell.CascadeWindows() &lt;br /&gt;        $tipTitle = &lt;span style=' color: Maroon;'&gt;"Cascade windows"&lt;/span&gt; &lt;br /&gt;        $tipText = &lt;span style=' color: Maroon;'&gt;"Cascade all windows"&lt;/span&gt; &lt;br /&gt;    }) &lt;br /&gt;    $miTileH.add_Click({ &lt;br /&gt;        $shell.TileHorizontally() &lt;br /&gt;        $tipTitle = &lt;span style=' color: Maroon;'&gt;"Tile Horizontally"&lt;/span&gt; &lt;br /&gt;        $tipText = &lt;span style=' color: Maroon;'&gt;"Tile windows horizontally"&lt;/span&gt; &lt;br /&gt;    }) &lt;br /&gt;    $miTileV.add_Click({ &lt;br /&gt;        $shell.TileVertically() &lt;br /&gt;        $tipTitle = &lt;span style=' color: Maroon;'&gt;"Tile Vertically"&lt;/span&gt; &lt;br /&gt;        $tipText = &lt;span style=' color: Maroon;'&gt;"Tile windows vertically"&lt;/span&gt; &lt;br /&gt;    }) &lt;br /&gt;    $miExit.add_Click({ &lt;br /&gt;        $form.Close() &lt;br /&gt;        $NI.visible = $&lt;span style=' color: Maroon;'&gt;false&lt;/span&gt; &lt;br /&gt;    }) &lt;br /&gt;     &lt;br /&gt;    $ni.ShowBalloonTip(&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;, $tipTitle, $tipText, [System.Windows.Forms.ToolTipIcon]&lt;span style=' color: Maroon;'&gt;"Info"&lt;/span&gt;) &lt;br /&gt;&lt;br /&gt;    $NI.Visible = $True &lt;br /&gt;    $form.showDialog()   &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ShellUtil&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113176019260147503?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113176019260147503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113176019260147503' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113176019260147503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113176019260147503'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/show-desktop-in-msh-way.html' title='Show Desktop in MSH way'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113158566020184319</id><published>2005-11-09T20:10:00.000-05:00</published><updated>2005-11-10T00:51:27.726-05:00</updated><title type='text'>Speak, your mind... In Excel that is...</title><content type='html'>I think what i am posting is quite old of a stuff.&lt;br /&gt;But oh well... Like I care...&lt;br /&gt;&lt;br /&gt;Let excel "speak" what you type...&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; speak { &lt;br /&gt;    param([&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;] $text = &lt;span style=' color: Maroon;'&gt;"Hello, World!"&lt;/span&gt;) &lt;br /&gt;&lt;br /&gt;    $ex = &lt;span style=' color: Blue;'&gt;new-object&lt;/span&gt; -com excel.application &lt;br /&gt;    $ex.speech.speak($text, $&lt;span style=' color: Blue;'&gt;null&lt;/span&gt;, $&lt;span style=' color: Blue;'&gt;null&lt;/span&gt;, $&lt;span style=' color: Blue;'&gt;null&lt;/span&gt;) &lt;br /&gt;} &lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;now,&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style='color:Red;'&gt;MSH&lt;/span&gt;&amp;gt; speak "your mind..."&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Oh yeah, the problem is that, after each "speak", an instance of "excel" will be shown on your Task Manager.  So if you would like to spam "speak", create an instance of excel object "outside" of function speak, then use that excel object repeately.&lt;br /&gt;&lt;br /&gt;Bah, i am not sure how to dispose that $ex when it's out of scope of function speak yet.  I thought it was gonna be done automatically...  I guess i should mess around with scope, tomorrow...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113158566020184319?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113158566020184319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113158566020184319' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113158566020184319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113158566020184319'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/speak-your-mind-in-excel-that-is.html' title='Speak, your mind... In Excel that is...'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113147116406083799</id><published>2005-11-08T12:30:00.000-05:00</published><updated>2005-11-08T12:45:14.570-05:00</updated><title type='text'></title><content type='html'>&lt;a href="http://mow001.blogspot.com/2005/11/msh-start-function.html"&gt;/\/\o\/\/ on MSH (Monad): MSH start. Function&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Another fun msh script by "/\/\o\/\/".&lt;br /&gt;&lt;br /&gt;Here is a bit modified version that I have put on my "profile.msh".&lt;br /&gt;This one basically takes a directory to open Windows Explorer for.&lt;br /&gt;Default is the current directory so...&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style=' color: Green;'&gt;# original code author: /\/\o\/\/&lt;/span&gt; &lt;br /&gt;&lt;span style=' color: Blue;'&gt;function&lt;/span&gt; startHere { &lt;br /&gt;  param([&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;] $dir = (pwd).path) &lt;br /&gt;&lt;br /&gt;  $sh = &lt;span style=' color: Blue;'&gt;new-object&lt;/span&gt; -com shell.application &lt;br /&gt;  $sh.explore($dir)  &lt;br /&gt;} &lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113147116406083799?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113147116406083799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113147116406083799' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113147116406083799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113147116406083799'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/o-on-msh-monad-msh-start.html' title=''/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113142482273469645</id><published>2005-11-07T23:28:00.000-05:00</published><updated>2005-11-07T23:40:22.750-05:00</updated><title type='text'>Displaying Weather Info through RSS with MSH</title><content type='html'>Uhm, I have been trying to display Weather data through MSH scripting.&lt;br /&gt;Man, after struggling for 30 minutes, i got kind of tired and didn't event get to finish the fully working demo.&lt;br /&gt;&lt;br /&gt;I just have pasted something i have been fiddling around a bit(WARNING: hardcore hardcoding)&lt;br /&gt;&lt;br /&gt;Most of Form window code was copied from &lt;a href="http://mow001.blogspot.com/2005/10/msh-directory-watcher-with-popup.html"&gt; MSH directory watcher with popup-balloon&lt;/a&gt; and RSS part can be found from &lt;a href="http://www.proudlyserving.com/archives/2005/06/monad_and_rss_p.html"&gt;Monad and RSS, Part 2&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I was having trouble with getting a description for each "$rssData.rss.channel.item".  The description was in "CData" form and it wouldn't let me access the property named "#cdata-section".  I guess i just don't know how to access the property...  Bah, time to go and hit the usenet...&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")&lt;br /&gt;[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")&lt;br /&gt;&lt;br /&gt;function weather {&lt;br /&gt; $form = new-object System.Windows.Forms.Form&lt;br /&gt; $cm = new-object System.Windows.Forms.ContextMenu&lt;br /&gt; $miExit = new-object System.Windows.Forms.MenuItem&lt;br /&gt; $miRefresh = new-object System.Windows.Forms.MenuItem&lt;br /&gt; $ni = new-object System.Windows.Forms.NotifyIcon&lt;br /&gt;&lt;br /&gt; $form.ContextMenu = $cm&lt;br /&gt; $form.ContextMenu.MenuItems.Add($miRefresh)&lt;br /&gt; $form.ContextMenu.MenuItems.Add($miExit)&lt;br /&gt; $form.ShowInTaskbar = $false&lt;br /&gt; $form.WindowState = "minimized"&lt;br /&gt; $form.add_Load({ &lt;br /&gt;  $wc = new-object System.Net.WebClient&lt;br /&gt;  $uri = "http://weather.msn.com/RSS.aspx?wealocations=wc:USNY0833&amp;weadegreetype=F"&lt;br /&gt;  $rssData = [xml] $wc.DownloadString($uri)&lt;br /&gt;&lt;br /&gt;  $title = $rssData.rss.channel.title&lt;br /&gt;  $desc = $rssData.rss.channel.item[0].title&lt;br /&gt;&lt;br /&gt;  $ni.ShowBalloonTip(100, $title, $desc, [system.windows.forms.ToolTipIcon]"Info")&lt;br /&gt; })&lt;br /&gt;&lt;br /&gt; $ni = $ni&lt;br /&gt; $ni.Icon = new-object System.Drawing.Icon("c:\msh\icons\test.ico")&lt;br /&gt; $ni.ContextMenu = $cm&lt;br /&gt;&lt;br /&gt; $miRefresh.Index = 0&lt;br /&gt; $miRefresh.Text = "&amp;Refresh"&lt;br /&gt; $miRefresh.add_Click({&lt;br /&gt;  $wc = new-object System.Net.WebClient&lt;br /&gt;  $uri = "http://weather.msn.com/RSS.aspx?wealocations=wc:USNY0833&amp;weadegreetype=F"&lt;br /&gt;  $rssData = [xml] $wc.DownloadString($uri)&lt;br /&gt;&lt;br /&gt;  $title = $rssData.rss.channel.title&lt;br /&gt;  $desc = $rssData.rss.channel.item[0].title&lt;br /&gt;&lt;br /&gt;  $ni.ShowBalloonTip(100, $title, $desc, [system.windows.forms.ToolTipIcon]"Info")&lt;br /&gt; })&lt;br /&gt;&lt;br /&gt; $miExit.Index = 1&lt;br /&gt; $miExit.Text = "E&amp;xit"&lt;br /&gt; $miExit.add_Click({ $form.Close() })&lt;br /&gt;&lt;br /&gt; $ni.visible = $true&lt;br /&gt; $form.showDialog()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;weather&lt;br /&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113142482273469645?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113142482273469645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113142482273469645' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113142482273469645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113142482273469645'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/displaying-weather-info-through-rss.html' title='Displaying Weather Info through RSS with MSH'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113130444570350181</id><published>2005-11-06T14:12:00.000-05:00</published><updated>2005-11-06T14:26:24.030-05:00</updated><title type='text'>MSDN monad blog</title><content type='html'>I think i will just start checking out the official &lt;a href="http://blogs.msdn.com/monad/default.aspx"&gt;monad technology blog&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Seems quite interesting...&lt;br /&gt;&lt;br /&gt;Wait a second.&lt;br /&gt;What about &lt;a href="http://www.reskit.net/monad/"&gt;Reskit-MSH&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Keeping track with&lt;br /&gt;&lt;a href="http://mow001.blogspot.com/"&gt;/\/\o\/\/&lt;/a&gt; is getting harder and harder for him coming up with all the new stuff to play around with...&lt;br /&gt;&lt;br /&gt;If you go to &lt;a href="http://groups.google.com/group/microsoft.public.windows.server.scripting"&gt;MS Scripting on Google Newsgroup&lt;/a&gt;, you can see a lot of useful questions posted concerning MSH.  Ah, IIRC, the most notable poster seems to be "/\/\o\/\/"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113130444570350181?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113130444570350181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113130444570350181' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113130444570350181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113130444570350181'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/msdn-monad-blog.html' title='MSDN monad blog'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113108646761517641</id><published>2005-11-04T01:41:00.000-05:00</published><updated>2005-11-04T01:46:48.223-05:00</updated><title type='text'>/\/\o\/\/ on MSH (Monad): MSH directory watcher with popup-balloon</title><content type='html'>&lt;a href="http://mow001.blogspot.com/2005/10/msh-directory-watcher-with-popup.html"&gt;/\/\o\/\/ on MSH (Monad): MSH directory watcher with popup-balloon&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now, here is some short, but a very serious script written by /\/\o\/\/&lt;br /&gt;&lt;br /&gt;The page basically deals with a script which monitors a directory(which is passed as an argument) for and displays this "Balloon" tip at icon tray when the watching directory has been changed.&lt;br /&gt;&lt;br /&gt;If you simply copy and paste the code on that page, it won't work as expected by throwing an error. Ah, gosh, it was because path to an icon file for NotifyIcon object wasn't there(since /\/\o\/\/ had hardcoded it as "g:\monad\mow.ico".&lt;br /&gt;&lt;br /&gt;And also if you copy the whole script including the comment, it will generate an error so make sure that you save the whole script either as a file + .msh or copy and paste excluding the comment to run...(hey, but don't forget about who the original author[/\/\o\/\/] of the script is...)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have modified the code a bit for more events(deleted and created) and also added "Start Monitoring" &amp; "Stop Monitoring" context menu for NotifyIcon($NI in /\/\o\/\/'s code) object.&lt;br /&gt;&lt;br /&gt;For feeling a bit buzzed from beer, i will be posting the modified source later.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113108646761517641?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113108646761517641/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113108646761517641' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113108646761517641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113108646761517641'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/11/o-on-msh-monad-msh-directory-watcher.html' title='/\/\o\/\/ on MSH (Monad): MSH directory watcher with popup-balloon'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18213836.post-113011821513668315</id><published>2005-10-23T21:39:00.000-04:00</published><updated>2005-10-24T18:57:27.706-04:00</updated><title type='text'>Msh fun~</title><content type='html'>Ok, i am currently trying out MSH beta 2.&lt;br /&gt;&lt;br /&gt;There is this d00d called "Mow"(spelled as "/\/\o\/\/") and he has some fun stuff.&lt;br /&gt;If you go to &lt;a href="http://mow001.blogspot.com/2005/10/playing-with-my-object-from-msh.html"&gt;Mow's blog&lt;/a&gt;  he has posted some fun and possibly useful MSH tricks.&lt;br /&gt;&lt;br /&gt;The title of his blog is called &lt;a href="http://mow001.blogspot.com/"&gt;&lt;pre&gt;/\/\o\/\/ on MSH(Monad), Playing with MY-Object from MSH&lt;/pre&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Enjoy everyone~&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18213836-113011821513668315?l=monadblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://monadblog.blogspot.com/feeds/113011821513668315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18213836&amp;postID=113011821513668315' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113011821513668315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18213836/posts/default/113011821513668315'/><link rel='alternate' type='text/html' href='http://monadblog.blogspot.com/2005/10/msh-fun.html' title='Msh fun~'/><author><name>Sung Meister</name><uri>http://www.blogger.com/profile/05010801354846302850</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
