Wednesday, March 07, 2012

PowerShell Version 3–Updatable Help (continued)

In a recent blog article I discussed the new updatable help feature of PowerShell V3. In that post I described the Update-Help cmdlet and shows how you use that cmdlet to up date your help information. The Update-Help cmdlet knows how to go online to find, download and install updated help information for both the core PowerShell modules plus any additional modules on your system. The PowerShell V3 module feature enables Get-Help to know (or be told!) where to look for updated material for each module, and does what is needed!

But what if you are offline, or you are in an air-gap network, isolated from the Internet. Well, obviously, in that situation, Update-Help can not go online and get the necessary updates. But PowerShell does provide a cmdlet, Save-Help, that can get the necessary help information and can store it. You can then copy somewhere Update-Help can then find – in the case of an airgap network, you could copy the help information to a memory stick, then use sneaker-ware to copy that material onto the airgap network.  Let’s take a look at both these aspects.

To save the help files, you use Save-Help, specifying a destination path (where you want the files saved). Optionally, you can specify the UI culture for which you want to get updated help. Specifying the –Verbose switch provides more output describing what Save-Help is doing. By default, you can run Save-Help or Update-Help just once per day (per machine). To over ride this, use the –force parameter.

Here’s what Save-Help looks like in my Windows 7 workstation:

 

SNAGHTML1f74f896

As you can see from this screenshot, PowerShell gets the files and stores them in the path folder, which then looks like this:

SNAGHTML1f79c392

Each PowerShell module has the two files that make up the extensible help for that module:

  • An XML file – this identifies the UI version of the help content (found in the XML).
  • A cab file – containing updated MAML and about_* files. Each file in the cab file represents something to be moved (later) by update help.

Each pair of files is named using a simple naming convention of : <module name>_<module guid>_<ui culture>_<helpinfotype, where <helpinfotype> is either HelpContent (in which case the file has a .CAB extension), or HelpInfo (in which case the file has a .XML extension).

You will notice that when I got the help, Save-Help could not find help for the module TFL. That’s mainly because that help information has not yet been written and saved in EN-US locale (well, not yet anyway!). I will do another blog post at some point where I explain how to add updatable help to your module.

To install this help on the air-gap network or machine, or one you want to update offline, you first have to save the files to somewhere you can later access them from the network/machine. As I suggest above, a USB memory stick can be used to transport them (or CD, etc). Once you have the files moved to their appropriate place, you use Update-Help, specifying the SourcePath parameter and providing the path to where the help files are available. The update would look something like this:

SNAGHTML1f8d8193

The Update-Help cmdlet (when verbose is specified), displays the XML files parsed and whether or not the associated HelpInfo file was processed and the help files in the CAB file that have been moved to their appropriate location.

 

Technorati Tags: ,,

Pluralsight Course–Formatting with PowerShell

I’ve just finished creating my latest course for Pluralsight, entitled Formatting with PowerShell. The course looks at how you can get great output from PowerShell  - including both defaults and what you can do to improve your output.

Formatting, to my mind, is the art and science of presenting data to your target audience. Great looking output not only is easier to read and consume, but it often gives (possibly unearned) credibility!  PowerShell does a lot of things by default, making it the superior tool for the IT Pro. This course shows you how you can get the most out of what PowerShell provides by default, but also what you can do to over ride these defaults.

The course has 6 modules:

Module 1 – Introducing .ToString(). The core of PowerShell (and .NET) formatting is the .ToString() method. I regard the .ToString() method as the basis for all formatting in PowerShell, so it’s important to understand this .NET feature. The module looks as using .ToString to format numbers, dates, time spans and enums.

Module 2 – Composite Format Strings. This is a feature, leveraged from within .NET that I use a lot. We look at what makes up a composite format string and how to use the –f operator to format strings.

Module 3 – Formatting In the Pipeline. This module looks at how you can use the Format-* commands to format objects coming from the pipeline.

Module 4 – Using Hash Tables. Hash tables can be used to improve the output, particularly output generated by Format-Table and Format-List. We look at these hash tables and provide examples as to how they work.

Module 5 – Format Files and Display XML. Default formatting in PowerShell is based on format files and display XML. This module looks at how you can write your own format files, both to change default output and to create new views for your own, or existing, data types.

Module 6 – Other Output Mechanisms. This final module looks at the other ways you can data out of PowerShell, including using the Out-* cmdlets, CSV and CliXML for persisting objects and both HTML and Office document output.

Each module has demos, best practices and provides a great summary. The course material includes the slides and all the demos which you get depending on what level of Pluralsight membership you have.

The course is finished and is going through the production phase which shouldn’t take too long – I expect the course to be on the web site this week. I have to say, the guys at Pluralsight are pretty good not only about making sure the course is high quality, but that all the bits are where you want them! I’m impressed overall with their people and their process. They make me want to write more material for them!

And a call out to TechSmith (www.techsmith.com). The course is recorded using Techsmith’s Camtasia and the screen shots captured using Techsmith’s SnagIt product. I could not have recorded this course without these two great products. If you are developing presentation or training course material, you should be looking at these two products. Once you have them, you’ll fall in love with them!  Thanks TechSmith!!

Sunday, March 04, 2012

Invoking a PowerShell Command from within a program–How Do They DO That?

One of the aspects of the Monad Manifesto was its advocating building GUIs on top of PowerShell. For some devs and fewer IT Pros, the mechanism is pretty clear and straightforward. But for a lot, it’s a bit of a black art. In this article, I’ll look at how they do that, but I’ll demostrate by doing it in PowerShell (with a pointer to seeing it in C#).

Running PowerShell within your executable program (irrespective of it being a GUI or a console application), involves 3 objects:

  • Runspace – a runspace is the operating environment pipelines. A pipeline runs within a runspace.
  • Pipeline – a pipeline is used to invoke commands.
  • Command – a cmdlet or script that gets added to a pipeline to run in a run space

Each of these three objects are found within the System.Management.Automation.RunSpaces namespace and are pretty easy to create and manage. The descriptions of these objects in MSDN are a little thin in and could usefully be improved with more examples.

Here’s a script that illustrates this (analysis is below the script)

###
#   Create a PowerShell runspace and open it
$rs = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
$rs.open()

#   Create a Pipeline
$Pipeline= $rs.CreatePipeline()

#   Create a command and add parameters
$cmd = New-Object system.management.automation.runspaces.command "Get-Process"
$cmd.Parameters.Add("Name", "Power*")

#   Add the first command to the Pipeline
$Pipeline.Commands.Add($cmd)

#   Invoke the pipeline
$collection = $pipeline.invoke()

#   See what's there
$collection
###

So what does this script do? Well first, it uses the runspace factory ( a feature built into .NET)  to create a new runspace on the local machine. Once created, the script opens the runspace for use.

Next we use the runspace object to create a new pipeline. We create a new  command object using New-Object. The command object is meant to run the  Get-Process  cmdlet and has a parameter (-Name) which for this run will have a value of ‘Power*’). 

After the command is added to the pipeline, the pipeline is invoked. Invoking the pipelines involves PowerShell, in effect, to run the Get-Process cmdlet with the appropriate parameters and return a result. That result, which is the same as you get running the command locally, is an array of objects that match the globbed name parameter (i.e. it would match PowerShell, PowerShell_ISE, PowerPoint, etc).

If you want the pipeline to have more than one command, that’s easy too. Suppose you wanted to support the output we obtained above? In other words, suppose you want to get the effect of “Get-Process –Name Power* | Sort-Object –Property CPU”? That’s easy. Just before invoking the pipeline above, just add the following:

#    Create a second command and add parameters
$cmd2 = new-object system.management.automation.runspaces.command "Sort-Object"
$cmd2.Parameters.Add("Property", "CPU")

#    Add the second command to the Pipeline
$pipeline.Commands.Add($cmd2)

It’s actually pretty easy, if you understand how to manage the three key objects involved. If you think about it, the sequence the script goes through is pretty much what PowerShell itself is doing when you are sitting at the console. The console is a little more complex, but most of the real magic is in the runspace itself and that is something the script and developers in general just leverage the feature.

An interesting aspect here is that all three objects are created using different approaches. The runspace is created by a static method on the runspace factory class, the pipeline was obtained by calling the runspace object’s method, CreatePipeline, and the command object(s) are created using New-Object.

So where might this be useful to an IT Pro. Probably not a lot of direct use – since PowerShell is doing all this for you (i.e. creating the run space, managing the pipeline and pipeline commands within, and marshal the output from the execution into something sensible at the console).  But I hope this might be of assistance to developers that are getting into PowerShell for the first time and want to integrate it into their applications.

Friday, March 02, 2012

PowerShell Version 3 Updatable Help Content

PowerShell has always had good in-box help. Each cmdlet has extensive documentation, complete with syntax and parameter details and plenty of good examples. As with all documentation, updating the help content has not been easy – or as easy as you might imagine.

With the decision to move PowerShell inside Windows, the help text has become almost read-only. If you think about the relative importance of changing help text post release, updates are not critical, so they don’t go out as part of the monthly update cycle. They don’t meet the bar for a Service Pack either. The bottom line for V2 in-box help text is that it’s effectively frozen till Win8 ships. The PowerShell team have partly worked around this by updating the on-line help, and giving the Get-Help cmdlet the ability to display, nearly seamlessly, the on-line help (i.e. use the –Online parameter to Get-Help).

For Version 3, PowerShell has updateable help content. To update your help text, you just type Update-Help and the cmdlet goes on-line and pulls down help not only for the core PowerShell cmdlets, but also for any module you have loaded on your system! That’s really cool!! This ships today with the new Version 3 update for earlier OSs and the new Win8 client/server beta.

As with many great features, there come some provisos and gotcha:

  • Help content is not installed by default. When you implement the MSU to add PowerShell 3 CTP to your older system or when you load Windows 8, there is only a bare skeleton of help information available. Much of this tells you to update your help. This decision is not going to change – you have to run Update-Help to update help. Microsoft may, I understand, consider doing some things via say Group Policy, but that’s not been confirmed.
  • UI Locale matters to Update-Help. Update-Help will look for help contents in the same language as your current locale. This is a problem for the Win8 beta since the number of languages supported by the beta is limited. I want en-GB content, based on my current locale, but there is none. There is, en-us, so I must specify explicitly the UI culture of the help I want to download.
  • You need admin rights to run Update-Help successfully. So use an elevated PowerShell prompt.
  • You need Internet access to get to the help information. You can, however, get the help content from the internet, place it somewhere, then use the –SourcePath or the –LIteralPath parameters to tell Update-Help where to find the Help source information.
  • Update-Help provides minimal output by default. Use the –Verbose parameter to Update-Help to see more of what’s going on.
  • Update-Help limits usage to once a day. By default, you cant’ update help more than once per day. This is to minimise the load on the MS servers providing this information. You and force Update-Help to run by specifing the –Force parameter to Update-Help.

WIth all this said here’s what Update-Help looks like on my system:

Before…

image

Updating Help:

image

And after…

image

In summary. PowerShell has updatable help and will use it moving forward. There are some small tricks to making it work for you, especially during the Win8 beta phase. But it’s a great feature and I love it already.

Thursday, March 01, 2012

PowerShell V3 Beta now available for down-level Operating Systems

Unless you’re in a cave deep in the moutains somewhere (in which case you won’t read this anyway!), you know that Microsoft has now released the first beta of Windows 8 client and server. Personally, I downloaded the server beta yesterday and am busy playing with it. Over the weekend, I will load it native on my laptop (brave man that I am).

One of the key features for me of both the server and client editions is the new beta of PowerShell V3. Microsoft has also poduced versions of the PowerShell beta for Vista/Server 2008 and Windows 7/Server 2008 R2. These contain all the same builtin cmdlets as you get with WIndows 8, without the addons only contained in WIndows 8. I am using this build now on my main workstations that are not yet running Windows 8.

You can get these beta builds at http://www.microsoft.com/download/en/details.aspx?id=28998. Note there are separate builds for the 2 OS sets and for 32 vs 64 bit systems. Be careful over which version you download.  And read the release notes carefully (when MS publishes them).

So far this new build continues the excellent work done in the past and is rock solid for me, albeit with a few areas where I think there’s more work that needs doing. Performance, for example, in a few places is not what it should be. And the debate over how help should be added into to box continues (I’ll document this issue in a blog post tomorrow). This all bodes very well for V3 being a great addition to the family!

So if you are using an older OS, consider downloading and using the latest PowerShell update. If nothing else, the new ISE is so good, it’s really worth it. Naturally, exercise due caution as this is a beta, etc. Having said that, it’s an excellent next step that I’ve put on all my key machines.

Wednesday, February 29, 2012

PowerShell, the ETS and Type XML

One of (the many!) cool features of PowerShell is the ETS, the Extensible Type System. With the ETS, you are able to create new types and, perhaps more importantly, extend existing types simply and easily.  The ETS is one of the key ways that PowerShell provides a level of consistency in the objects you use, despite that consistency being lacking in the underlying object(s).

Take, for example the System.Array type. This type, in .NET, has a Length property, but does not have a Count property. Why not, I hear you ask. The answer is simple: the folks that developed this type did not include it. Sadly, the .NET Framework has lots of little (potential) inconsistencies. In a perfect world, we can fix this – and with PowerShell we can!

Using a bit of XML, you can easily add an alias called Count to the Name property. This XML looks like this:

<Types>
    <Type>
        <Name>System.Array</Name>
        <Members>
            <AliasProperty>
                <Name>Count</Name>
                <ReferencedMemberName>Length</ReferencedMemberName>
            </AliasProperty>
        </Members>
    </Type>
</Types>

To add this alias, you just save this XML (say to My.Types.PS1XML) then import this definition into PowerShell by using the Update-Type cmdlet. Now as it happens you don’t need to do this for System.Array, as Microsoft has already provided this extension (and a bunch more) in $PSHome/Types.PS1XML, which is loaded by default. But I think you get the idea.

If you want to see the ETS at work, take some time to study this Types.PS1XML file – it shows  how PowerShell extends .NET specifically to provide a level of consistency across objects that is missing from the .NET Framework itself. Some cool things this file does include:

  • Provides .ToString() methods for a number of types (these definitions override the default .ToString() method in the type itself.
  • Add new properties implemented as PowerShell script blocks. For example, System.Management.Automation.PSDrive is extended with a script property called Used (but for PSdrive objects that are based on the FileSystem provider only!). 
  • Define default Property Sets for some objects. These then become the properties that PowerShell display by default. For example, the default property set for System.ServiceProcess.ServiceController is defined as; Status, Name and DisplayName. If you run the Get-Service cmdlet, you will see these three properties are displayed by default.

The ETS enables you to adapt ANY .NET type – adding in properties that don’t exist, or overriding the ones that do exist. These new properties can be a new alias (as noted above), a script property, or a script method. One particular place I’ve found recently where this is useful is on the output of Get-ADComputer. If you run Get-ADComputer (Part of the active directory module shipped by Microsoft with Server 2008 R2), the output is objects of the type Microsoft.ActiveDirectory.Management.ADComputer. This type has a Name property for the computer name (which is the host name) as well as a DNSHostName. This is all fine and well, but many of the cmdlets that take a computer name (and send the command to that computer for processing) use the ComputerName property. So how do you use Get-ADComputer to get computer names and then pipe the output to other cmdlets when the property names differ?  For example, suppose you want to find  One way is like this:

Get-ADComputer –filter * | foreach {Get-Service –name ‘DNS Server’ –computername $_.name} …

That’s a bit messy – as we wanted the computer name to be returned from Get-ADComputer and used in the call to Get-Service. By default, this is not possible. However, if we do some magic type adaptation, we could add an alias property to the ServiceController object, like this:

<Types>
<Type>
    <Name>Microsoft.ActiveDirectory.Management.ADComputer</Name>
    <Members>
          <AliasProperty>
                <Name>ComputerName</Name>
                <ReferencedMemberName>Name</ReferencedMemberName>
            </AliasProperty>           
    </Members>
</Type>
</Types>

Once you import this definition (use Update-TypeData specifying the filename including this definition), then, we can do this:

Get-AdComputer -Filter * |
   
Get-Service -Name "DNS Server" -ErrorAction SilentlyContinue |
        Format-Table MachineName, Displayname, Status –Autosize

On my system, this produces the following output:

MachineName DisplayName  Status
----------- -----------  ------
COOKHAM1    DNS Server  Running
TALLGUY2    DNS Server  Running

As you can see, Type XML is the key to exploiting the ETS. With Type XML and the ETS, POwershell and you can find consistency in places where it’s never existed. What a cool feature!

[Later]

Thanks for the comment from JB. If, like JB,  you were wondering why I a using the MachineName property in the call to Format Table. The ComputernName property is initially created on the objects produced by Get-ADComputer. The Get-Service cmdlet takes the objets from the pipeline and gets the ComputerName property the sends the service request to the computer named by computer name. However, Get-Service produces objects that return the ComputerName in a Machinename property (even though the CMDLET parameter is Computername)!  Rather demonstrating my point about consistent inconsistency! I could add another alias property to the ServiceController type, which is not a bad idea!

 

Technorati Tags: ,,

Wednesday, February 08, 2012

Get-ChildItem and the–Include and –Filter parameters

I saw a good question the other day in the PowerShell.Com Learn PowerShell Forum which related to using –Include when calling Get-ChildItem (or DIR, or LS!). The OP had a bunch of files in a folder (C:\Data) and wanted to get at just the *.txt files as follows:

Get-ChildItem –Path C:\Data –Include *.Txt

But it did not work – it returned no files at all (even though there were some in the folder. The reason is clear if you read the great help text closely: the Include switch is only active if you are also using the –Recurse parameter! Another small to make is that the –include property specifies a globbed string (I.e. a file name specified with Wild cards) and not a regular expression.

The simplest way to just get the text files form a single folder would be:

Get-ChildItem –Path C:\Data\*.Txt

Another way to get just the Text files in a given folder would be to use the –Filter parameter. The –Filter parameter  is sent to the provider and is used to qualify the –Path value. You can call it like:

Get-ChildItem –Path C:\Data\ –Filter *.Txt

So you have two ways to get a subset of files in a folder using a form of early filtering. And if you use –Recurse (thus are getting all the files in a folder and it’s child folders), you can use either the –Include or –Filter parameters. They give the same result. Well almost. If you use –Include *.txt, you only get the files which have an extension of .txt. Using  -Filter, you get a slightly different result as shown here:

Psh[Cookham8:C:\foo]>Get-ChildItem -path c:\DATA  -filter *.txt -recurse  -ea Silentlycontinue
    Directory: C:\DATA
Mode                LastWriteTime     Length Name                                                        
----                -------------     ------ ----                                      
-a---          2/5/2012   3:48 PM          0 copy.txtfoo                                                        
-a---          2/5/2012   3:48 PM          0 one.txt
-a---          2/5/2012   3:48 PM          0 three.txt
-a---          2/5/2012   3:48 PM          0 two.txt

As you can see, *.txt also copies *.txtfoo. I’m sure this is ‘by design’ but it doesn’t seem to map to my expectations. Still, in most cases, extensions do not overlap like this (of course PowerShell is an exception – with .PS1 and .PS1XML extenstions!).

As an alternative to using either –Filter or –Include, you could always get ALL the child items (e.g. all the file and folder objects in C:\Data), and pipe the output to Where-Object for further (later) filtering. This works, but as most IT admins know, early filtering tends to be more efficient. But the filtering done by –Filter may be surprising – If I use –Filter *.ps1, then PowerShell returns me all the PowerShell scripts in

The –Filter parameter also turns out to have an additional benefit. The value of Filter you specify is used by the provider to qualify the path value. By comparison, the –Include specifies a filter for PowerShell to apply. Thus, the –Filter parameter generates early, early filtering, whereas-Include is later early filtering! The performance difference between the two approaches turns out to be significant! I wrote a little script to calculate the costs of using the three methods, as follows:

# Test-Filtering.PS1
$start = get-date
$f = Get-ChildItem -path c:\windows  -include *ps1 -recurse -ea Silentlycontinue
$end = Get-Date
$time1=$end-$start
"Using -Include    : {0,4} files in {1,-6:n2} seconds" -f $f.count,$time1.totalseconds
$f| ft name,length

$start = get-date
$f=Get-ChildItem -path c:\windows  -filter *ps1 -recurse  -ea Silentlycontinue
$end = Get-Date
$time2=$end-$start
"Using -Filter     : {0,4} files in {1,-6:n2} seconds" -f $f.count,$time2.totalseconds
$f | ft name,length

$start = get-date
$f=Get-ChildItem -path c:\windows  -recurse  -ea Silentlycontinue | where {$_.extension -eq '.ps1'}
$end = Get-Date
$time3=$end-$start
"Using Where clause: {0,4} files in {1,-6:n2} seconds" -f $f.count,$time3.totalseconds

The results are here:

image

I have to say, the numbers were not what I was expecting! I was surprised how much faster –Filter turned out to be – around 3 times quicker than either –Include, or using late filtering. And compared to using –Include, late filtering is really not all that much slower.

 


Wednesday, February 01, 2012

Windows PowerShell PowerCamp–Helsinki March 10-11

Arrangements for this event in Helsinki are moving along nicely. Those very nice people at Sovelto, who are hosting the event, have put up a new web page around the event: see http://www.sovelto.fi/kurssit/Pages/PowerShell-PowerCamp.aspx (or to see this page in Finnish, go to : http://www.sovelto.fi/Kurssit/Kurssivalikoima/Pages/Kurssihaku.aspx?kurssiID=3647). These web pages have the Helsinki agenda and all the details of where/how to book, etc.

As you will see, the event is over the weekend of March 10 and 11 2010 at Sovelto’s offices in Helsinki. We’ll start at 9 both days. We will be including lunch, refreshments and breakfast both days, with a nice meal out and a bit of fun for the Saturday night (details will be announced soon – it should be fun!).

So if you are anywhere in the world and want to get a first class jump start to PowerShell, consider coming! We’ll even have PCs for all the attendees as well as a nice little goodie basket to take home!

Contact me if you have any questions – or better yet, contact Sovelto and book a place!

Monday, January 23, 2012

PowerShell PowerCamp Weekend–London–April 21-22 2012

As I noted in an earlier bog post,  I
’m pleased to be able to bring you a PowerShell PowerCamp weekend events in London in the not too distant future.  Here’s the details!

 

What is A PowerShell PowerCamp?
This fast paced weekend event covers all the key aspects of Windows PowerShell - from the command line and writing production-oriented scripts. We start with the basics including installation and configuration, formatting and providers and remoting. We then look at scripting, managing script libraries using modules, using objects, and finishing with the PowerShell features added into Windows. We finish with a look at PowerShell in the cloud and what’s coming with PowerShell V3.


The PowerCamp event is all lecture plus Q&A, with the opportunity to type along with the tutor. There are no formal labs.

What is the Agenda?
Day 1 – The Basics
• PowerShell Fundamentals – starting with the key elements of PowerShell (Cmdlets, Objects and the Pipeline) plus installation, setup, and profiles
• Discovery – finding your way and learning how to discover more
• Formatting – how to format output nicely – both by default and using hash tables and display XML
• Remoting – working with remote systems using PowerShell’s remoting capabilities
• Providers – getting into OS data stores via PSProviders
Day 2 – Diving Deeper
• Scripting Concepts – automating everyday tasks including PowerShell’s language constructs, error handling and debugging (both from the command line and using an IDE)
• Modules – managing PowerShell script libraries in the enterprise
• .NET/WMI/COM Objects – working with native objects
• PowerShell and Windows Client/Server – how you can use built in PowerShell cmdlets
• PowerShell in Key Microsoft Servers - a look at PowerShell today in SQL, SCVMM plus a look forward to the future with SharePoint 2010
• PowerShell and the cloud – this module looks at PowerShell in the cloud and how you can use PowerShell to manage cloud computing.
• PowerShell V3 – this final module shows you what’s new in PowerShell V3.

What does it cost?
The cost is £200 (+VAT at the prevailing rate) for the weekend. Meals and accommodation are not covered.

Where is the event going to take place?
The PowerShell PowerCamp is being held at Microsoft Cardinal Place, 100 Victoria Street in Victoria on the weekend of April 21-22 2012. Each day starts promptly at 09:00 and finishes up by 16:45.

PowerDrinks?
After Saturday’s session, attendees are invited to a small nearby public house for some lovely English ale.

Who is the tutor?
The PowerShell Weekend PowerCamp is delivered by Thomas Lee. Thomas is a veteran PowerShell MVP who has been involved in the PowerShell community since the very beginning. He provides training and consultancy around a range of Microsoft products, with a recent focus on PowerShell and Lync Server. Thomas runs PowerShell training courses around the world, and has been a speaker at conferences across the world for the past decade. In his spare time, he lives with his wife, daughter, wine cellar, and Grateful Dead live recordings archive in a small cottage in the English countryside. His Twitter handle is DoctorDNS and he maintains two blogs (Under the Stairs at http://tfl09.blogspot.com and PowerShell Scripts Blog at http://pshscripts.blogspot.com).

What do I need to bring
You need to bring a laptop PowerShell loaded. We suggest you have at least two VMs pre-configured (i.e. a Server 2008 R2 domain controller and a member server). And if you have access to the Windows 8 beta, bring along a Win8 VM for the look at PowerShell V3. The virtualisation software is not of concern – but you need 64-bit guest OS support. Thus you can use Hyper-V, VMware Workstation or Oracle’s Virtual Box.

How do I book?
Contact DoctorDNS@Gmail.com to book a place and to arrange for the invoice to be paid. Payment must be in cash, cheque or bank transfer – I don’t take credit cards.

More Details
Watch Thomas’s blog for any hot breaking news on the event.

 

Two New PowerShell PowerCamp Events Coming Soon

I’m pleased to be able to bring you two more PowerShell PowerCamp weekend events in the upcoming months:

  • HELSINKI – Weekend of March 10-11 2012 – takes place in the offices of Sovelto, at Ratapihantie 11 (1st floor) in Helsinki. I do not have pricing or this event yet but will post details as soon as I get them. We will have something interesting for Saturday night to be included in the price.
  • LONDON – Weekend of 21-22 April 2012 – takes place at Microsoft’s Cardinal Place offices in London Victoria. We’ll all repair off to a local hostelry on the Saturday evening for a beer or three.

I’ll post more details about each event soon.

 

Friday, December 16, 2011

Lync 2010 Lync Mobile Client

Earlier this week, I blogged about the new Lync mobile client – i.e. client software for smart phones and the iPad. As of mid afternoon today, the client sets for WP7 and Android are shipping. From the comments I hear from users – this software is fairly trivial to install and does what it says! It also adds value to the Office 365 proposition. I can’t wait to use it against Lync Online!

There is one small gotcha – in order to use this new client against your on-premise Lync deployment – well first you have to have one (the client is of no use unless you have an implementation of Lync to use it against). And secondly, assuming you have Lync working, there are upgrades to the product, the mobility service, that need to be added. And there are a couple of DNS changes to be made and a new firewall port to open. Those are pretty straightforward but of course have to be done before the client can work against your implementation of Lync.  For those of you on Office 365, all that work is done – although you need to make DNS changes if you are hosting the DNS for your Office 365 domain.

I’ve seen very few issues reported so far, and the general consensus in Twitter at least is that the client is working well. About the only negative comment was from Michael Smith (Market Management Director at Cisco). Of course he got it wrong ranting about no Android/IOS support, which seemed to blunt most of his argument. One point he does pick up on is  that there is no VOIP feature in the client.

To support VOIP, the mobile handset would have to either support wireless and have wireless connectivity or use the cellular data channel against your data plan. Those are the only two ways to get the IP datagrams carrying VOIP signaling and data from your phone to the other end of the connection. If you are using wireless to connect, then VOIP calls will constitute additional bandwidth both from the phone to the WAP and from the WAP into your enterprise network. If your wireless infrastructure is not up the mark, you end up with poor service and a bunch of unhappy users. Using your cellular carrier for the actual phone call reduces that risk.  If you were using VOIP over wireless, then the battery life takes a hit.  Battery life on my phone is sure improved when I turn the WIFI off!

Using VOIP over the cellular carrier’s data channel might have once made sense – sadly the days of unlimited data may well be gone with most mobile phone companies imposing limits and costs. And don’t get me started about how expensive it can be to use data roaming when outside the UK or worse outside the EU (around half my working time is spent outside the UK). Even with the inflated call cost outside the UK, using the mobile network for the phone calls is a lot cheaper. Outside the EU, we can pay over £6/mb for cellular data. A one minute call over such a link would consume in the region of 4.6mb (assuming RTA Narrowband is used) for the call and would cost around £14.00. Worst case rates on O2 are £1.79/minute for the cellular call. A no brainer to me – plus the company pays the cost of the call.

A VOIP client in the product might have been nice to have, but from an Enterprise perspective, using Call-From-Work makes more sense as provides better assurance over call quality and lower help desk calls. These users do, of course,have Skype which works perfectly as a VOIP phone for those times when they can tether on the USB to keep the battery topped up and are on a well provisioned wireless network. With Skype now belonging to Microsoft, I can’t help but thinking that one day we will have the combined client – but exactly what Skype will do to Lync is a topic for another day. 

But in the meantime, it looks like another nice addition to the Lync family aimed at.  I am anxious to try it out!

Technorati Tags: ,,

Tuesday, December 13, 2011

PowerShell ISE Script Explorer–Get it Today

Microsoft has just released the latest CTP release of the Microsoft Script Explorer for Windows PowerShell. This is an add-in to the ISE that enables you to search for scripts within the PowerShell ISE. With this release, you can:

  • Search online repositories including PoshCode and Technet
  • Establish and search local and corporate script repositories
  • Filter search by location and product relevance
  • Browse Community Resources, including the TechNet Wiki
  • Integrate community samples into corporate script library seamlessly

This CTP is based on an invitation – and I just happen to have one:

https://connect.microsoft.com/site1064/InvitationUse.aspx?ProgramID=7431&InvitationID=TL10-GX2K-3VFW

Click on this link and login to Connect. If you are not already resistered on Connect, you need to sign with a valid Microsoft LiveID.

So head on over, and try it out. Feel free to leave you comments – either here, or with Microsoft!

Technorati Tags: ,

PowerShell’s ++ and -- Operators (Redux)

A couple of days ago, I posted an article on PowerShell’s ++ and – operators. I grew up using programming languages that never implemented the auto increment/decrement operators, this was a neat new feature for me.

But I have had a couple of comments pointing out that these operators are not new, are in C# and what I describe is indeed by design. Of course they are right. The point I was making was aimed at those new to PowerShell and who probably do not have a background in programming.

For the avoidance in doubt, I know how these operators work and am well aware of them and their behavior. Smile But I do see many IT Pros that discover these operators for the first time in a PowerShell class – and it was a question I’d been asked that I posted about.  For those new to programming and to PowerShell, these two operators are a neat find and I advocate using them. But like many of PowerShell’s richer features, you have to know how they work.

 

Microsoft Begins Shipping the Lync Mobile Client

For those of us in the Lync world, the release of a Lync client for mobile phones has been long awaited. Although Microsoft released Lync 2010 to the market over a year ago, there has been no mobile client up till now. The lack of a mobile client has been a point some Microsoft competitors have been quick to jump on. But starting earlier this week, the client is slowly rolling out on 5 key platforms (Windows phone, iPhone, iPad, Android and Nokia Symbian).  Thus far, Microsoft has only released Lync for the Windows Phone – the others are shown as ‘coming soon’ on the Mobile Clients for Microsoft Lync web page.

Microsoft cites 4 key features of the new Lync mobile client:

  • Join conferences with a single touch - no access code or pin number is required.
  • Stay connected, while controlling your availability – you can see who's available at a glance and connect over IM, email or a call. You can also set your own status and notification settings so you can stay in touch while protecting your "off-work" time.
  • Communicate with others using a single, consistent identity. The Call-via-work feature allows outbound calls using your Enterprise Voice number, making it easier for others to recognize calls from the Lync mobile client.
  • Connect with confidence through channel encryption, transport layer security (TLS) support, and perimeter/internal network protection that help safeguard your communications.

To the dismay of some, there is no VOIP client – all phone calls to/from the device have to be made over the cellular network, but Call from work and One Number reach do make that a little less expensive.  It appears that the Call via Work feature will not be shipped with Android.

Like so many things Microsoft, the client is not something you can just load from the relevant store and have it work – you do need some work on your Lync implementation and need to install the latest cumulative updates (CU4 in particular) to get the necessary services up and running that support the motile client.

These requirements are spelt out in yet another TechNet article: http://technet.microsoft.com/en-us/library/hh690988.aspx. You will need to do some work against your DNS servers to ensure automatic discovery and sign-in works properly. Although this is pretty straightforward, it is work that needs to be planned for and carried out. If you are an Office 365 user and Microsoft is managing your DNS, the work appears to be already done. I host DNS externally to Office 365 but it took me just a few minutes to adjust my DNS settings as needed. You also have to install and configure the mobility service (in CU4), and update your voice policy to support use of the mobile client.

One important gotcha that might be easy to overlook: You need to include certain (new and additional) SAN entries on your key servers. In particular you need to adjust SAN entries on the certificates in your Director pool, your Front End Pool and the reverse proxy. If you use public certificates for any of these systems, you may have to buy an updated certificate for the RP system. 

In closing, it’s worth noting that the mobile client does NOT provide 100% of the features of the Lync desktop client.  You can see a good comparison of the various clients at: http://technet.microsoft.com/en-us/library/hh691004.aspx. Some features that are NOT provided by the mobile client (as documented in TechNet) include:

  • Caching multiple users account information on the same device
  • Modify Contacts List
  • Tag contacts for status change alerts
  • Control privacy relationships
  • Log IM conversations in Exchange/Outlook
  • Use dial-in audio conferencing
  • Transfer a call
  • Call a response group
  • Support E911
  • Client side IM archiving and client side recording

I can’t wait to get my hands on the client and to use it against my Office 365 account (tfl@reskit.onmicrosoft.com). From all I’ve heard from those who have the client – it does what it says it does and thus far appears stable and resilient. I look forward to using the client - As an iPhone user, I will have to patient. After all – I’ve been waiting 14 months or so for this client a few more days wait is not the end of the world! It will make a nice Christmas present!

Monday, December 12, 2011

Using PowerShell’s ++ (and–-) operator–Take Care

I got a great question the other week in a PowerShell class regarding the ++ operator. The delegated to know if there was any difference between $variable++ and ++$variable. In PowerShell, the operator ++ says, effect to add one to the variable it’s attached to.  So specifying $loopcounter++ as a statement on it’s own (e.g. inside a loop would just add one to the loop counter variable. 

I don’t use the ++ operator a lot – When I was first learning programming, the languages we had (assembler, Cobol, RPG, Fortran and Algol) never had these operators. So incrementing loop counters freestanding is about all I ever do. But I started playing and found some interesting things about ++!

First, looking at my most common use case, $variable++ and ++$variable seem to be the same as this code illustrates:

$lc=0;1..10 | foreach {$lc++};"Loop counter: $lc"
$lc=0;1..10 | foreach {++$lc};"Loop counter: $lc"

produces

Loop counter: 10
Loop counter: 10

 

So at that level the formats are equivalent in function.  And for the most part, the ++ operator used before or after the variable name produces similar results. But not in all cases. Consider the following code fragment:

“Case 1”;$lc=0;1..5 | foreach {"{0}" -f $lc++};"Loop counter: $lc"
”Case 2”;$lc=0;1..5 | foreach {"{0}" -f ++$lc};"Loop counter: $lc"

These two code fragments do not produce the same output. In the first case, the value of LC is formatted into the string, THEN it’s incremented, whereas in the later case, the incrementing occurs before the formatting. Thus the output looks like this:

Case 1
0
1
2
3
4
Loop counter: 5
Case 2
1
2
3
4
5
Loop counter: 5

So as you can see ++$variable is not always the same as $variable++.  Another curiosity of PowerShell that you just have to know!

[Later]

Of course, if you know C# or some other newer languages ++/-- may be old hat to you. And thanks for the comments that came from this post!

Wednesday, December 07, 2011

PowerShell 3.0 CTP2 Released for Windows 7/Server2008R2

I’ve been on the road a bit lately, and missed last week’s shipment of the PowerShell V3 CTP2. This is the second ''beta'’ of the upcoming PowerShell Version 3. At present this only works in Windows 7 and Server 2008 R2. There are, as I understand it, no plans for this to back-port to Vista and Server 2008 R2. I do hope that MSFT DO release a version for Vista and Server 2008 RTM but we’ll see.

In the meantime, the new version has lots of bug fixes, seems quite a bit faster and in general seems more mature than CTP1. In my case, the install was a bit confusing as I’m doing a multi-boot to VHD with Windows 8 on my laptop, unfortunately, one of the partitions (of course my default) ran out of disk space so after installing the update, recovering from the out of disk space issue, Win 7 thought the update had failed. I fixed the boot problem, then re-installed the update. From the looks of it, the update also does an in-place upgrade of the CTP 1 process (although the release notes ask you to remove CTP1 first).

The new CTP has a wealth of update to the console and the ISE. With the ISE, the output and input panes are merged into a single console like pane. Very useful and much easier to use. Read the release notes for a summary of what’s new.

You can get the various downloads that make up the release here: http://www.microsoft.com/download/en/details.aspx?id=27548. From that page you can get the 64-bit and 32-bit installation packages (.MSU files), release notes and a PDF containing a description of the new ISE Features and a description of the new features in Out-Gridview.

I love this product!

Technorati Tags:

Saturday, November 12, 2011

Using the PowerShell ISE–two cool finds

I’ve been using PowerShell’s Integrated Scripting Environment ever since it was in beta. Despite being relatively slow to load, it sure beats using Notepad for simple script development/debugging. The colour coding alone makes it even more useful! I love how you can add functionality to the editor via object model. It’s neat how that object model is exposed inside PowerShell as the $ISE variable – and how easy it is to use it to add menu items (and keyboard short cuts for the menu items).

A freely available module that offers a lot of ISE customisation is the IsePack, which is part of the PowerShellPack mega-module issued by Microsoft as part of the Windows 7 Resource Kit. You can download the full PowerShellPack from http://archive.msdn.microsoft.com/PowerShellPack. The PowerShellPack module is actually a set of 10 sub-modules. You can import the entire module (Import-Module PowerShellPack) or the sub-components. In my ISE Profile file, I add the ISE pack in specifically (Import-Module IsePack). That in turn exposes me an additional Add-On menu item, ISEPACK. This menu contains a set of sub-menus which add a lot of features to the ISE.

My two cool finds are partly what’s in IsePack and what I could easily add to it. The ISEPack creates a number of functions based on the ISE’s object model. It then leverages those in additional functions that PowerShell associates with menu items and keyboard shortcuts when the module is imported. And since the module is just a text file – you can easily edit it and add more features.

The first cool find is the Search-Bing function, which is associated with a menu item (Add-ons/IsePack/Search-Bing) and a keyboard shortcut (Ctrl-B). The Search-Bing function uses a lower level function,  Select-CurrentText, that gets the text that is currently selected somewhere on the ISE', then pipes it to copy of IE which points http://www.bing.com/search?q=$_. Thus, if I have the text ‘ToString’ highlighed in an open editor window, and hit Ctrl, I get a Bing Search Page, like this:

image

 

The second cool thing was how easy it was to ammend the IsePack module to add a Search-Google function. In the IsePack.PSM1 file, there’s a fragment of code that implements the Search-Bing feature (and adds it to the menu) This fragement is part of a larger script, but here’s the starting poing:

"Search-Bing" = {
        $Shell = New-Object -ComObject Shell.Application
        Select-CurrentText | Where-Object { $_ } | ForEach-Object {
            $shell.ShellExecute("
http://www.bing.com/search?q=$_")
        }
    } | Add-Member NoteProperty ShortcutKey "CTRL+B" –PassThru

 

As you can see, Search-Bing is associated with a script block that first opens the currently configured Web Browser (FireFox in my case). Then it executes a Bing Search on the currently selected text. This results in the search window coming up. So how hard was it to add to add a Search-Google? Trivial as it turns out. I just added the following text directly below the Search-Bing definition:

    "Search-Google" = {
        $Shell = New-Object -ComObject Shell.Application
        Select-CurrentText | Where-Object { $_ } | ForEach-Object {
            $shell.ShellExecute("http://www.Google.com/search?q=$_")
        }
    } | Add-Member NoteProperty ShortcutKey "CTRL+Shift+G" -PassThru

 

Sadly, Ctrl+G was already taken by something (a puzzle for another day!), so I used Ctrl+Shift+G and that brings up something like this:

image

 

As I am currently working on my next Pluralsight course on Formatting with PowerShell, I’m finding a need to look stuff up in MSDN and these two functions sure are useful to me!

Wednesday, November 09, 2011

PowerShell PowerCamp–A great weekend!!!

I’m now recovered from the most recent PowerShell PowerCamp – an intense two days of PowerShell training. I ran the event in London last weekend, and had 21 booked. Sadly there were two very last minute cancellations, so we we ended up with 19 eager souls. We walked through the basics of PowerShell at the command line on the Saturday, then on Sunday, started looking at scripting and other enterprise aspects of PowerShell. And on Sunday, we has Lync MVP superstar Tom Arbuthnot of Modality Systems in to talk some real world approaches to PowerShell.

On Saturday night we took over a small pub nearby, to the amusement of the locals, and continued chatting about PowerShell. I My lovely wife came up to London and we enjoyed a most interesting meal in Sobraine, a Russian restaurant in Victoria. Great food and very, um, interesting décor.

The delegates took home a memory stick with as many PowerShell goodies as I can find and will shortly be getting licenses for PowerGui professional and PowerShell Plus Pro, thanks to Quest and Idera!

I have no specific dates for the next PowerShell PowerCamp, but depending on interest, I would like to run another session sometime in the late spring (March/April). As ever, dates are tricky at that time of year what with half term and Easter, etc – but I’m sure we can find a good weekend should there be anyone wanting this level of training! And for those corporate readers – I’m happy to come to your place of work and run this same training for your team on your premises. If you have 6 or more delegates, this could be financially beneficial.

And in closing – a big thanks for Claire Smyth of Microsoft who was an enormous help in getting this event off the ground. Without her help and passion for the community, this event probably would not have happened! Thanks Claire!! And thanks too to Michael Sullivan for letting his hosting channel know about the event.

For any enquires about the next PowerCamp or running a PowerCamp privately, email me at DoctorDNS@Gmal.Com.

 

Technorati Tags: ,

Performance with PowerShell

Over the weekend, at the most recent PowerShell PowerCamp, I got to discussing the performance of PowerShell. The point I was making was that PowerShell made doing some things very easy, even though they were not performant. Two examples are the early filtering  of WMI data using –Filter (vs using Where-Object after you retrieve all the data from a remote machine) and the two variants of ForEach.

In the case of WMI, where you early filter properties/occurrences on the target machine, PowerShell has less data to serialize and transmit across the network. Also, late filtering requires more local memory, and additional processing. Thus I’d expect early filtering to be faster. We are thus comparing two statements which might look something like this:

Get-WMIObject win32_share -computer  Cookham1 -filter "Description='remote admin'"

versus

Get-WMIObject win32_share -computer  Cookham1  | Where {$_.description -eq 'remote admin'}

In the first example, only one share is returned from Cookham1, whereas in the second example multiple shares are returned and are then filtered locally (aka late filtering). If I wrap both of these commands in a Measure-Command, and do the operation a number of times, the code and results look like this:

 

Psh[Cookham8:fmt:\]>"Early Filter:"
" {0} ms"  -f  ((Measure-command {1..100 | foreach {
Get-WMIObject win32_share -computer  Cookham1 -filter "Description='remote admin'"}}).totalmilliseconds).tostring("f")

"Late filter:"
" {0} ms"  -f  ((Measure-command {1..100 | foreach {
Get-WMIObject win32_share -computer  Cookham1  | Where {$_.description -eq 'remote admin'}}}).totalmilliseconds).tostring("f")
Early Filter:
1948.91 ms
Late filter:
2715.44 ms

So the difference between late filter and early filter is around 28%, although if I run this test a few times, the numbers do vary a bit, but almost always early filtering is in the region of 20% faster.

But a much bigger difference was observed by Anita Boorboom, a Dutch SharePoint guru, in the second case, i.e. using For-Each-object (vs using ForEach in a pipeline).

When you use the foreach operator in a pipeline, PowerShell is able to optimise the creation of objects at one stage of a pipeline and their consumption in the next. Using Foreach-Object, you need to first persist all the objects you wish to iterate across, then perform the iteration. The latter clearly requires a bit more processing and it is likely to require more memory (which can be a bad thing if the collection of objects is large! I knew this, but Anita’s results were a little more than I was expecting, so I duplicated her scripts, well nearly, and found here results were indeed correct, like this:

$items = 1..10000
Write-Host "ForEach-Object: "
" {0} ms"  -f ((Measure-Command { $items | ForEach-Object { "Item: $_" } }).totalmilliseconds).tostring("f") 
Write-Host "Foreach: "
" {0} ms" -f ((Measure-Command {Foreach ($item in $items) { "Item: $item" }}).totalmilliseconds).tostring("f")
ForEach-Object:
  629.73 ms
Foreach:
31.84 ms

Thus the pipelined foreach is nearly 20 times faster for this experiment. I ran this code several times, and the multipler was consistently in the 20-30 times as fast range. That floored me. The For-Each Object does require PowerShell to instantiate every object in memory, then to iterate over it, vs iterating as it instantiates. But I did not expect a 20-30 fold difference in performance!

So it’s obvious that some language constructs will be a little more efficient, You also need to consider the time it takes to write the code, and how often it will be run.  In the first case above, I managed to save just over 750ms by using early WMI filtering. But it probably took me more than that just to write the code for early binding. And for a lot of admins that don’t know WMI very well, filtering using Where-Object is familiar and uses PowerShell Syntac (the –filter clause on Get-WMIObject used WQL which is different). In the second case, the difference was staggering. Of course, when the processing you want to apply to the collection members is non-trivial (i.e. more than a couple of lines of code), you often find the improvement in readability of the resulting script block to be worth considering. By using task oriented variable names, the resulting code is easier to read then when you use $_. And for some production orient5ed scripts, that improvement in readability may be worthwhile.

In summary, there always a lot of different ways to achieve the same result in PowerShell. I advocate using what is easiest for you to remember. At the same time, PowerShell can provide some big performance differences between the approaches – and it pays to know more!

Technorati Tags: ,

Thursday, November 03, 2011

PowerShell PowerCamp Soon Come!

We’re locked and loaded for this week-end’s PowerShell PowerCamp event in London this Saturday and Sunday November 5 and 6 in London Victoria. We had a few last minute cancellations, but in all we have 19 folks signed up (and room for 2 more late bookers should you be interested). And owing to landlord works, the event has been moved to the building next door – but everything will be alight on the night as they say.

I’ve got a box of nice new memory sticks to copy all the collateral onto – one for each attendee. I’ve also got copies of some cool software for all who turn up as well. And in the unlikely event that Wiley gets their act together and the books actually arrive, I may have a copy or two of our PowerShell Bible book (but as Wiley ship books by surface, it’s a month after the copies shipping but they’ve still not arrived).

Should you be at a loose end this weekend and fancy a two day PowerShell boot camp, please email me (DoctorDNS@Gmail.com) as due to the two late cancellations, there’s still a bit of room. Alternatively, I am hoping to do another weekend event in the Spring (and will announce it as soon as I get the dates etc. lined up which will probably not be till late-November/early-December).

And for any PowerShell addicts who happen to find themselves in London on Saturday, we’ll be having PowerDrinks (also known as beer and other drinks!)starting at 17:15 on Saturday. Send me mail and I’ll send you the co-ordinates of the event!

Technorati Tags: ,,

Tuesday, November 01, 2011

Introduction to WMI and PowerShell – A NEW Pluralsight Course

I am quite pleased to be able to announce I’ve finished my first video class for Pluralsight, Introduction to WMI and PowerShell. It’s now available for viewing for Pluralsight subscribers.  I’ve been watching it a bit this morning and it’s not bad, if I do say so myself. Smile

The course is a total of 2:29, and is broken down into 5 modules as follows:

  • Introduction to WMI and PowerShell (21:28) – Describes WMI in Windows and discusses some of the key WMI exploration tools. The module then looks at PowerShell support for WMI in PowerShell V3, and describes the WMI cmdlets. The module finishes with some of the gotchas you need to be aware of when using WMI with PowerShell.
  • Using PowerShell and WMI  (34:37) This module looks at accessing WMI data, including instances, instance properties and methods, WMI classes, and static class methods. We cover the use of the key WMI cmdlets and explain the use of Type Accelerators.
  • Practical PowerShell (24:42)  - This module looks at the range of data you can use in WMI. We show key namespaces and key classes you might leverage. The module also looks at some of the security settings you might make use of when using WMI in a Enterprise environment.
  • Using WMI Query Language (29:36) – Describes the WMI Query Language and how to use it with the PowerShell WMI cmdlets.
  • WMI Eventing (39:16) - This final module looks at accessing WMI events. It shows how to create both temporary and permanent event subscribers for intrinsic, extrinsic, and timer events. It also explains all those terms and shows how to leverage WMI’s eventing subsystem.

So if you are currently a Pluralsight subscriber, why not consider it? If nothing else, take the free trial – 10 days access to the entire library, including this course.

And also: a big thank you to Alexandar Nikolic (@alexandair on Twitter) for his proof reading of the course – much appreciated!!

Thursday, October 27, 2011

Pluralsight WebCast on Using WMI from PowerShell

I got a fun call last night – PluralSight has a regular webcast but this week’s presenter has had personal issues – and would I like to do the webcast? Well SURE!  When don’t I like the chance to talk about PowerShell!?!?

As it turns out, this is perfect timing - I’ve just finished developing a new PluralSight course, Using WMI from PowerShell which goes LIVE today. So this web cast is a great opportunity to tell you a bit more about the course, and hopefully tempt you to download it and consume the video! I’ll enjoy talking about it!!

The webcast is at 11:00 US Eastern Time – 16:00 time here in the UK. Please join us at: http://www.pluralsight-training.net/microsoft/Webcasts

Friday, October 07, 2011

Using PowerShell with WMI Events

I’ve been working on a WMI and PowerShell video course for PluralSight (due out soon) and am today working on the last bit of the course which covers Events. I found an MSDN sample written in VBScript. Here’s the VBScript:

Sub SINK_OnObjectReady(objObject, objAsyncContext)
    WScript.Echo (objObject.TargetInstance.Message)
End Sub

Set objWMIServices = GetObject( _
    "WinMgmts:{impersonationLevel=impersonate, (security)}") 

Set sink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
 
objWMIServices.ExecNotificationQueryAsync sink, _
    "SELECT * FROM __InstanceCreationEvent " & _
    "WHERE TargetInstance ISA 'Win32_NTLogEvent' "
I spent some time looking at this trying to get my head around what it was actually doing.   Turns out that translating it into PowerShell was fairly simple. Here’s the PowerShell code:

$query = "SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' "

Register-WmiEvent -Source Demo1 -Query $query -Action {
                Write-Host "Log Event occurred"
                Write-Host "EVENT MESSAGE"
                Write-Host $event.SourceEventArgs.NewEvent.TargetInstance.Message}

Even with the nice spacing that turns 9 hard to understand lines of VB SCript into 2 LONG lines of PowerShell (or 5 as it’s so nicely spaced out here). I could have written it as a one-liner had I wished to go for compactness – but I think spacing it out a bit helps in terms of understaning.

The bottom line for me is that PowerShell is just so much easier to understand – you register for an event. A query tells you which event. And when that event fires, you take some action. Job done.

Technorati Tags: ,

Wednesday, September 28, 2011

PowerShell PowerCamp–November 5/6–Filling Fast

I first started advertising this event in August, with a blog post and some tweets. Since then, we’ve had a good response with 14 folks booked so far. At this rate, we may need a bigger room. I’m going up Saturday to check out the meeting room to ensure all is OK!

In the mean time,  here’s the details of the event:

What is it?

This fast paced weekend event covers all the key aspects of Windows PowerShell - from the command line and writing production-oriented scripts. We start with the basics including installation and configuration, formatting and providers and remoting. We then look at scripting, managing script libraries using modules, using objects, and finishing with the PowerShell features added into Windows. We finish with a look at PowerShell in the cloud and what’s coming with PowerShell 3.  The event will be all lecture, with the opportunity to type along with the tutor.

What is the Agenda?
Day 1 – The Basics
•  PowerShell Fundamentals – starting with the key elements of PowerShell (Cmdlets, Objects and the Pipeline) plus installation, setup, and profiles
•  Discovery – finding your way and learning how to discover more
•  Formatting – how to format output nicely – both by default and using hash tables and display XML
•  Remoting – working with remote systems using PowerShell’s remoting capabilities
•  Providers – getting into OS data stores via PSProviders
Day 2 – Diving Deeper
•  Scripting Concepts – automating everyday tasks including PowerShell’s language constructs, error handling and debugging (both from the command line and using an IDE)
•  Modules – managing PowerShell script libraries in the enterprise
•  .NET/WMI/COM Objects – working with native objects
•  PowerShell and Windows Client/Server – how you can use built in PowerShell cmdlets
•  PowerShell in Key Microsoft Servers - a look at PowerShell today in SQL, SCVMM plus a look forward to the future with SharePoint 2010
•  PowerShell and the cloud – this module looks at PowerShell in the cloud and how you can use PowerShell to manage cloud computing.
•  PowerShell 3 – this final module will show you what’s new in PowerShell V3, based on the the latest Beta of Windows 8

What will it cost?
The cost is £200 (+VAT at the prevailing rate) for the weekend. Meals and accommodation are not covered.

Where is the event going to take place?
The PowerShell PowerCamp will be held at Microsoft Cardinal Place, 100 Victoria Street in Victoria on the weekend of November 5/6 2011.

Who is the tutor?
The PowerShell Weekend PowerCamp will be delivered by Thomas Lee. Thomas is a veteran PowerShell MVP who has been involved in the PowerShell community since the very beginning. He provides training and consultancy around a range of Microsoft products, with a recent focus on PowerShell and Lync Server. Thomas runs PowerShell training courses around the world, and has been a speaker at conferences across the world for the past decade. His Twitter handle is DoctorDNS and he maintains two blogs (Under the Stairs at http://tfl09.blogspot.com and PowerShell Scripts Blog at http://pshscripts.blogspot.com)

PowerBeers after Class on Saturday
I'll also be leading the class across the street to the pub for a beer after we finish on Saturday. I’d be happy to buy the first round! You (and I ) will probably need by then!

Special Guest
I have arranged for a guest PowerShell advocate, Tom Arbuthnot, to come along and add some additional flavour to the event. Tom works for Modality, a great UK Unified Comms consultancy and will be looking both at PowerShell in Lync abut also at wider issues. He’s should be fun!

PowerBeers after Class
I'll also be leading the class across the street to the pub for a beer after we finish on Saturday. I’d be happy to buy the first round! You (and I ) will probably need by then!

What do I need to bring
You need to bring a laptop with at least two VMs pre-configured. The first should be a Server 2008 R2 domain controller and the other one a member server. And if you have access to the Windows 8 beta, bring along a Win8 VM for the look at PowerShell V3. The virtualisation software is not of concern – but you need 64-bit guest OS support. Thus you can use Hyper-V, VMware Workstation or Oracle’s Virtual Box.

Take Aways
After the event, I’ll provide you with a USB memory key with as many of the free PowerShell Goodies as I possibly can. Attendees will also get an NFR license to both Idera’s PowerShell Plus Professional and Quest’s PowerGui Professional.

How do I book?
Contact DoctorDNS@Gmail.com to book a place and to arrange for the invoice to be paid. Payment will need to be cash, cheque or bank transfer – I don’t take credit cards. I will need to limit the total number of attendees, so book now!


More Details
Continue to read this blog!!

I look forward to a few more bookings and two cracking days of PowerShell.