Welcome to MSDN Blogs Sign in | Join | Help

April 2006 - Posts

How PowerShell Formatting and Outputting REALLY works

<WIZARD WARNING> Dreeschkind posted a question in the Microsoft.Public.Windows.Server.Scripting newsgroup about how PowerShell formatting worked with Select. He saw some behavior that he thought was a bug. Here is what he saw: PoSh C:\> gps |
Posted by PowerShellTeam | 3 Comments
Filed under: ,

Use of Wildcards in PowerShell Formating

MMS in San Diego was a great conference! I met lots of customers that asked lots of great questions. I was demonstrating PowerShell's WMI support when a customer asked about controlling the output. The problem was that PowerShell was showing all the WMI

PowerShell interview on Tom's Hardware

Check out the interview that Scott Ottaway and I did with Scott Fulton of Tom's Hardware : http://www.tgdaily.com/2006/04/25/powershell_windows_command_line_to_ship_q4/ Tom's has consistently been a source of good information about this project - going

Bruce Payette is writing a book: PowerShell in Action

Superstar Bruce Payette is writing a book focused on the whats and whys of the language called PowerShell in Action . Bruce is the dev lead on the language and is a walking encyclopedia of computer languages. I have the honor of being a technical reviewer

IDE for PowerShell and a new book

PowerShell is a great interactive shell and a great scripting language. That said, the feedback from the scripting community has been very clear: they want/need a PowerShell Scripting IDE. As such, I was very happy to finally have something to say about
Posted by PowerShellTeam | 1 Comments
Filed under: ,

The new TabExpansion feature...

One of the nicest new features in the latest drop of Windows PowerShell is enhanced tab-completion. We now tab-complete properties on variables and parameters on cmdlets in addition to the old filename completion. But that's not the interesting part.
Posted by PowerShellTeam | 12 Comments
Filed under: , ,

Exposing the Power of .NET in a Admin-friendly way

One of our primary goals for Monad was to: "Expose the power of .NET in an Admin-friendly way" . The challenges of systems administration are large and growing at the same time organizations are under ever more pressure to reduce costs and do more with
Posted by PowerShellTeam | 13 Comments
Filed under: , ,

Dynamically loading assemblies in mshsnapins.

In Monad, mshsnapins can be installed in a different directory from the Monad executables. At runtime, the Monad engine will load the mshsnapin assembly and its referenced assemblies based on application base information provided during mshsnapin installation.

Exclude, Include, Filter Parameters - How to make sense of these

So how come we have three ways to filter a path in most of the core cmdlets such as in the get-item cmdlet. It is important to understand that exclude, include, and filter offer different levels of filtering. So let’s give a few examples of how get-item

How to Access or Modify StartUp Items in the Window Registry

Some applications launch themselves whenever you start your computer and load Windows. In most cases, this is the desired behavior. However in some instances, malicious programs such as spyware, Trojans, worms, viruses load in this manner and hijack your

The worlds easiest way to create/install MshSnapins

Hopefully you've read the previous entries on how to create MshSnapins to include your own cmdlets/providers without having to create an entire separate executable (custom shell). If you didn't or if you did and you don't feel like writing the extra MshSnapin

Monad breaking change announcement: Approved verb names enforcement.

In order to prevent a mass usability nightmare with developers picking their own improvised cmdlet verbs, the Monad team, based on customer feedback, decided to enforce the use approved verbs. The idea is to provide a more uniform and consistent interface

Write-Progress

Tony has a very cool series of Monad-oriented blog entries at: http://mshforfun.blogspot.com/ . I was fascinated by this one: http://mshforfun.blogspot.com/2005/12/ncbi-blastn-under-msh-command-line.html which exposes the NCBI BLAST tool via a command

.NET types

In response to the recent Days till Xmas post, applepwc asked the question > where can I find more ".NET types"?I mean is there a list of ".NET type" available in monad? Excellent question but there are a number of aspects to it so let's break it down:

Monad cmdlet cleanup update

As Jeff re y mentioned in an earlier Blog “ Finding which parameters are used the most ” The Monad team is in the process of cleaning up our cmdlets to promote a more consistent user experience . The following two areas which we are focused on might have

Days till Xmas

My daughter loves christmas. She often asks me, "how long is it till christmas?" The problem with that is that I'm one of those people that can barely remember what year it is much less the date. Well, it is one thing to be a flawed person and its another

Finding which parameters are used the most

We are in the process of cleaning up our Cmdlets and ensuring that they are consistent. One of the things we want to do is the ensure that we provide Aliases for ParameterNames. As a general rule, parameternames are not pithy. That is great for reading

Invoking Scriptblocks from C#

Last time somebody asked for an example of a C# method that took a scriptblock. First of all, there’s one very important thing you have to know about scriptblocks as they are currently implemented. They can’t be invoked outside of a runspace. Any attempt

Minding Path Inputs in a Cmdlet

When I was a Monad neophyte, I was asked to write a Cmdlet taking a file path as a parameter. A big mistake I made was not keeping in mind that in Monad the FileSystem provider was just one of the many providers. (This makes Monad different from many

Adding help for cmdlets in a MshSnapIn

Now that you know how to create an MshSnapIn, you might want to add help content for all those cmdlets that you developed and get them displayed by “get-help” cmdlet. To add help content you must know how a Monad Cmdlet Help file looks. See any of the

Ensuring Script Portability with #requires

With the MshSnapIn model in Beta 3, there is no gaurantee that a certain Cmdlet or Provider, apart from those in the default MshSnapIns, is available at any point. There could be a number of reasons. The MshSnapIn may not have been installed. The MshSnapIn

Single Shell vs Custom Shell

With Monad Beta 3 release, we've introduced the concept of the "single shell". What is a single shell? "One shell to rule them all ... and in the darkness..." (Sorry I can't stop saying that quote everytime I hear "single shell"!) Well rather than having

Mshsnapin (part 2): developing a mshsnapin.

To develop a mshsnapin, you can use following three simple steps, Create a class derived from MshSnapIn class. Build an assembly to contain the mshsnapin class created in step1 and also other cmdlet/provider classes to be included in the mshsnapin. Install

Mshsnapin (part 1): usage of mshsnapin commands.

Latest beta3 release of monad added the capability of adding/removing cmdlets and providers in current running session through mshsnapins. Mshsnapin is a logic group of cmdlets and providers can be manipulate as a unit in monad engine. Following commands

Using Monad for logon scripts

In case you were wondering, yes, you can use Monad for your logon scripts. You can't just assign a .MSH file as a logon script however, since only file types with file associations work as logon scripts. Monad installation doesn't create a file association

Managing non-terminating errors

Most errors which occur in your working scripts are likely to be "non-terminating". This means that Monad just reports the error and the command keeps running. ("Terminating" errors such as syntax errors will halt the command and, in some cases, the entire

Getting MSDN help urls for .NET BCL types and Members

Often when playing with .Net objects in Monad, I need to use MSDN class library reference to learn how to use a particular type and its members. Now, I have my bookmarks and favorite search engine but I always thought it would be cool if get-member cmdlet

Check Spelling Script

After reading Marcel's introductory piece on ScriptBlock, I decided to rewrite an old script of mine that checks the spelling of all text files in a directory. Here is what I came out with. #region Parse a line to a list of words $StringFind = {param

Finding out what determines which properties are displayed

MoW, a Monad newsgroup regular, asked why only the Caption, Name and PeakUsage properties were displayed from the command “get-WMIObject Win32_PageFileUsage” while the output object had a lot more properties. I think it is worth it to explain in details

GetObject()

Monad provides a way to create new com objects with new-object $ie = New-Object -ComObject InternetExplorer.Application $ie.Navigate2( http://blogs.msdn.com/monad ) $ie.Visible=1 Great but what about if you want to bind to an existing object? Where is

Base64 Encode/Decode a string

Today I came across http://scripts.readify.net/ . This sight is focused on Monad and MSH and is starting a collection of scripts at: http://scripts.readify.net/Scripts.aspx . You should visit their site and let them know what type of scripts would be

Monitor the Event Log

Administrators often want to monitor the event logs and look for specific error conditions. The most capable way to do this, of course, is to use a dedicated monitoring application such as Microsoft Operations Manager , or get down-and-dirty with the
Posted by PowerShellTeam | 0 Comments
Filed under:

Verb-Noun vs Noun-Verb

Kurt asked the question "why not Noun-Verb vs Verb-Noun" in his post: http://blogs.msdn.com/monad/archive/2006/02/16/533522.aspx#574708 There are lots of answers to this some better than others. Let me rattle off a couple of them: VMS DCL/AS400 . Issac
Posted by PowerShellTeam | 1 Comments
Filed under:

Is it safe to use ALIASES in scripts?

In our newsgroup (Microsoft.Public.Windows.Server.Scripting) , Mark Ayers asked the question: > Shouldn't best practice for scripts be full command name? The answer is YES, NO, and MAYBE. YES - Full names provide the most readable experience for scripts.
Posted by PowerShellTeam | 1 Comments
Filed under: , ,

How does Select-String work with Pipelines of objects?

<Edited to convert Match-String to Select-String 7/9/2006> In our newsgroup (Microsoft.Public.Windows.Server.Scripting) , Vasu asked about how Select-string works in pipelines: Here is what I observe: 1. MSH C:\> get-alias ..truncated.. Alias

Sunday morning drive with my hair on fire: Types/Community/Synthetic types/Democracy/Cool XML tricks

Exploring types is a pain! Monad provides Get-Member which makes it pretty nice to explore an OBJECT but if you want to explore that object's type, you have to use the capabilities of the System.RuntimeType class. Let me make that distinction a little
Posted by PowerShellTeam | 1 Comments
Filed under: , , ,

Why did you do that? $VAR/ {} / Weak Intellisense

I strongly encourage people to let us know where we could be doing better and to let us know if we are getting into the weeds. I believe that being open to such bad news is core to the the virtuous cycle of self improvement so such feedback provides opportunities
Posted by PowerShellTeam | 1 Comments
Filed under: ,

Comparative Examples in MSH and KSH

M ost shells (such as Windows CMD.EXE and the UNIX shells SH, KSH, CSH, and BASH) operate by executing a command or utility in a new process, and presenting the results (or errors) to the user as text. Text-based processing is the way in which system
Posted by PowerShellTeam | 46 Comments
Filed under: , ,

Working with Sort-Object Cmdlet

In this blog I will try to explain different features of sort-object(Sort) cmdlet. For the purpose of this blog, I assume the following objects exist: MSH C:\temp\monad> $a,$b,$c,$d Score Name ----- ---- 100 John 90 Henry 90 Tom 80 David From the definition
Posted by PowerShellTeam | 0 Comments
Filed under: ,

A bit about Scriptblocks

When scripting with MSH one of the most useful things to know about are scriptblocks (lambda functions). Scriptblocks are compiled bits of MSH script which you can pass around and invoke whenever you feel like it. They turn out to be so useful that if

Monad portal in Script Center.

Most scripters are familar with Microsoft script center. Script center now has a portal for Microsoft Command Shell. You can access the portal at http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx -Arul Kumaravel [ Edit: Monad has now been renamed

PINVOKE or accessing WIN32 APIs

In the very early days of Monad, we focused on a world where everyone would publish Cmdlets and providers. Cmdlets and providers were designed around providing the best user experience. They provide the right, high-level, task-oriented abstractions that

Using-Culture -Culture culture -Script {scriptblock}

One of the traditional challenges with scripting is dealing with different CULTURES. Imagine the case where you are writing a script and you'll have to parse datetime string from different cultures. If it was just one culture, you could set the process

Debugging Monad Scripts, Part 7 (Final): How Traps Work

Did your command or script fail and/or report an error? We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong. In this series of blog entries, I will present some

Debugging Monad Scripts, Part 5: Preferences and Commandline Options

Did your command or script fail and/or report an error? We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong. In this series of blog entries, I will present some

Debugging Monad Scripts, Part 6: Trace-Expression, Breakpoint Script

Did your command or script fail and/or report an error? We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong. In this series of blog entries, I will present some

Debugging Monad Scripts, Part 4: set-mshdebug

Did your command or script fail and/or report an error? We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong. In this series of blog entries, I will present some

Debugging Monad Scripts, Part 2: $error

Did your command or script fail and/or report an error? We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong. In this series of blog entries, I will present some

Debugging Monad Scripts, Part 3: Write-Host

Did your command or script fail and/or report an error? We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong. In this series of blog entries, I will present some

Debugging Monad Scripts, Part 1: Teminating vs. Non-Terminating, ErrorRecord

Did your command or script fail and/or report an error? We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong. In this series of blog entries, I will present some

Image Conversion

I needed to convert some images from bmp to gif for a web site I've been working on. I figured that I could script this pretty easy - here's what I came up with. It's a little more general than I needed, and I thought it might be useful to others. Anyway,

Duplicate Files 2

A long time ago I posted a filter (AddNote) for adding notes to objects. Some time later I posted a function (Get-MD5) for calculating the MD5 hash of a file and somebody asked how that could be used in a script to list all the files in a given folder

Duplicate Files

Need a way to check if two files are the same? Calculate a hash of the files. Here is one way to do it: ## Calculates the hash of a file and returns it as a string. function Get-MD5([System.IO.FileInfo] $file = $(throw 'Usage: Get-MD5 [System.IO.FileInfo]'))

Adding Notes

A while back I mentioned that there was a way of adding notes to objects in the shell. Here is one way to do it: ## Adds a note to the pipeline input. filter AddNote([string] $name, $value) { $mshObj = [System.Management.Automation.MshObject] $_; $note

MshObject and Methods that take object

Every once in a while people ( including me) run into trouble calling methods that take object. Why? Well, as I told you earlier objects in MSH are wrapped by an invisible MshObject. As it turns out that this invisible object is not always so invisible.

Support for Existing apps in Monad

Monad provides strong support for existing apps and technology. If you use native cmdline exes, vbscripts, batch files, perl scripts etc to manage and maintain windows, you can pretty much use them the same way from monad as you would from cmd.exe. For

Did you know? #4

Did you know that you can access most of the Cmdlet base class APIs through script using the $executioncontext variable? -Jeff Jones

Did you know? #3

Did you know that you can put constraints on variables using the same attributes as cmdlet parameters? Unfortunately we had to postpone the language support for this but you can still do it using new-object. MSH > $a = "foo" MSH > $varA = get-variable

Did you know? #1

Did you know that you can access the content of a provider using the variable syntax? For instance, you can get and set the contents of a file just by doing the following: MSH > ${c:\temp\foo.txt} = "bar" MSH > ${c:\temp\foo.txt} bar MSH > Note,

Did you know? #2

Did you know that you can make a variable automatically propagate to new scopes by using the AllScope option? Normally when you enter a new scope variables are not copied from the parent scope. Instead we do a lookup for the variable when requested. Anytime

Introduction to MshObject

If you’ve ever worked with the Monad APIs then you’ve no doubt seen a type called System.Management.Automation.MshObject. I’m not going to go into all the details of what it is because that would take me more time than I have right now and there are people

Windows PowerShell (Monad) Has Arrived

I just got out of Bob Muglia's keynote speech where he formally announced Windows PowerShell (previously known as Monad). The key things he announced are: Monad (MSH) has a new name: Windows PowerShell Windows PowerShell will RTW (Web download) in Q4
Posted by arulk | 34 Comments
 
Page view tracker