Cash Talks - BS Walks RSS 2.0
 Wednesday, October 10, 2007

I created a DasBlog Content filter for creating Wikipedia links.  DasBlog Content filters are simple search and replace items.  It does stuff like replace ; -) with  <img alt="; -)" src="smilies/wink.gif">   (I inserted a space after ; so it would not get performed)  It can also do RegEx patterns as used in this example.

I created a derivative of their Google search that searches Wikipedia instead.  The Find Pattern is

\$w\((?<expr>[\w\s\d]+)\)

RegEx patterns. 

<a href="http://en.wikipedia.org/wiki/Special:Search?search=${expr}">${expr}</a>

This allows you to type $ w(Microsoft)  and it will create Microsoft.   (I inserted a space after $ so it would not get performed)

The imbedded HTML is:

<a href=”http://en.wikipedia.org/wiki/Special:Search?search=Microsoft”>Microsoft</a>

Multi Word with spaces works great too.  If you want it to go to a page it must be exact and unique. 

Wednesday, October 10, 2007 1:57:55 PM (Central Daylight Time, UTC-05:00)  #    Comments [0] - Trackback
DasBlog
 Tuesday, October 09, 2007

PowerGUI's editor is nice and lightweight.  I wasn't crazy about the colors in the syntax highlighting.

Luckily, this can be customized.  Not with a GUI, but at least in the configuration XML - PowerShellSyntax.xml.  I replaced the Styles section with the following:


      <Styles>
<Style Key="ReservedWordStyle" ForeColor="Blue" Bold="True" /> 
<Style Key="OperatorStyle" ForeColor="Red" />
<Style Key="OperatorWordStyle" ForeColor="Red" />
<Style Key="VariableStyle" ForeColor="Purple" /> 
<Style Key="CmdletStyle" ForeColor="Black" Bold="True" /> 
<Style Key="NetClassStaticStyle" ForeColor="teal" /> 
<Style Key="NetClassStaticMethodStyle" ForeColor="saddlebrown" /> 
<Style Key="CmdletParamStyle" Italic="True" ForeColor="Black" /> 
<Style Key="NumberStyle" ForeColor="Black" /> 
<Style Key="StringDelimiterStyle" ForeColor="Green" /> 
<Style Key="StringDefaultStyle" ForeColor="Green" Bold="True" /> 
<Style Key="CommentDelimiterStyle" ForeColor="Maroon" /> 
<Style Key="CommentDefaultStyle" ForeColor="Maroon" /> 
<Style Key="AutoVars" ForeColor="Navy" />
</Styles>


A Sample Render looks like:


#########################################################################
# Some sample code

$strComputer = "."
$colItems = get-wmiobject -class "Win32_LoadOrderGroup" -namespace "root\CIMV2" `
   
-computername
$strComputer

foreach ($objItem in $colItems)
{
   write-host
"DriverEnabled: " $objItem.DriverEnabled 
   write-host
"GroupOrder: " $objItem.GroupOrder 
   write-host
"Name: " $objItem.Name write-host
}


I'm sure I'll tweak it, but I'm already happier using the product.

 

Tuesday, October 09, 2007 10:41:49 PM (Central Daylight Time, UTC-05:00)  #    Comments [0] - Trackback
Powershell

When I first saw PowerGUI I was suspicious.  Quest is a first rate company that is very proud of their tools.  I've personally drove the purchase of their tools for Oracle Development a few years back.

Quest made a Press Release for PowerGUI.  It doesn't really commit to keeping it free.  Besides, it's still Beta.  I figured the other foot would drop when it got released.  And by foot, I mean several hundred dollars of foot.

Dimitry Sotnikov recent post announces a new download - that's still Free!  Still slightly leery, I did some searching and found his commentary Why is Quest doing free PowerShell stuff?

While I can't imagine Quest committing to keeping it free, it looks like it is for now!

Don't get me wrong, I'm not a "profit is evil" kind of guy.  But I find it difficult to keep up with the license management for my team.  A product has to be core to the job and save a magnitude more time that it costs fooling with it.  Who knows, we might get addicted to it and maybe Quest will charge a hundred dollars or less for it.

Hopeful Microsoft will make the definitive editor for PowerShell.  Hey, maybe integrate into Visual Studio!  We pay thousands of dollars per developer per year and you would think an intellisense editor for PowerShell wouldn't be too much to ask for.  (I'm hoping Bruce will slap me down again and show me where I've missed it.)

Tuesday, October 09, 2007 7:54:23 PM (Central Daylight Time, UTC-05:00)  #    Comments [0] - Trackback
Powershell

Powershell provides easy string expansion such as:

$Name = "Cash"
$Msg = "$Name is in the house"

Not too surprising the value of $Msg is "Cash is in the house".

However, what if I want the variable $Msg to be "$Name is in the house" and expand the variable $Name later.  For example, This can be useful for template string.

First, to get the template created you need to suppress the string expansion.

$Msg = '$Name is in the house'

Obviously the Template string has to be properly escaped and ready to evaluate.  Next you have to get Invoke-Expression to expand the variable

$Name = "Cash"
write-host Invoke-Expression ('"' + $Msg + '"')   # - Cash is in the house
$Name = "The Dog"
write-host Invoke-Expression ('"' + $Msg + '"')   # - The Dog is in the house

The explanation is ('"' + $Msg + '"') builds out a string with quotes on both sides ready to be evaluated by Invoke-Expression.

UPDATE

I got slapped down within hours of my first blog posts by The Man.  I'll elevate his comment into my post:

While this technique will work, it's not recommended because of the problem of nested quotes. For example, if your template string was '"$name" is in the house', then you would get an error. PowerShell provides a .NET method to do this directly which is also available to scripts. Here's an example of how to use it:

PS (109) $template = '"$name" is in the house'
PS (110) $name = "Cash"
PS (111) $ExecutionContext.InvokeCommand.ExpandString($template)
Cash is in the house
PS (112) $name = "The dog"
PS (113) $ExecutionContext.InvokeCommand.ExpandString($template)
The dog is in the house

-bruce

=========================================================
Bruce Payette
Principal Developer, Windows PowerShell Team
Microsoft Corporation

Tuesday, October 09, 2007 1:50:06 PM (Central Daylight Time, UTC-05:00)  #    Comments [2] - Trackback
Powershell
Archive
<October 2007>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Cash Foley
Sign In
Statistics
Total Posts: 17
This Year: 0
This Month: 0
This Week: 0
Comments: 4
Themes
Pick a theme:
All Content © 2010, Cash Foley
DasBlog theme 'Business' created by Christoph De Baene (delarou)