February 2011 - Posts

DevConnections–Connections powered by Microsoft

The conference is in London 14-15 June and includes a number of PowerShell related sessions. There is also a pre-conference PowerShell workshop on 13 June delivered by Don Jones. Details can be found here

http://www.devconnections.com/shows/europe2011/default.aspx?s=174

 

I am hoping to arrange a PowerShell UG meeting with Don as the speaker while he is in London.  Details to follow.

Posted by RichardSiddaway | with no comments
Filed under:

UK PowerShell Group–March 2011

March 22 we have Tome Tanasovski presenting on Regular Expressions.

 

Tome is a Windows engineer for a market-leading global financial services firm in New York City. He is a recipient of the PowerShell MVP award, the founder and leader of the New York City PowerShell User group, a blogger, and a regular contributor to Microsoft's Windows PowerShell forum. He has been featured four times on Hey Scripting Guy, and he is currently working on the PowerShell Bible, which is due out in 2011 from Wiley. 

http://powertoe.wordpress.com

http://twitter.com/toenuff

 

His session description:

Regular Expressions have been employed by every serious scripting language for the past 15 years. PowerShell's adoption and implementation of Regular Expressions has ensured that it is taken seriously by serious scripters. The presentation will explore the history and syntax of regular expressions. It will give a deep dive into the PowerShell cmdlets that use Regular Expressions as well as the .NET native methods that can be invoked using PowerShell. It will give a detailed understanding of the internals of Microsoft's implementation of Regular Expressions and how it differs from other languages. Real-world scenarios for using regular expressions will be explored.

 

Live Meeting Details:


When: Tuesday, Mar 22, 2011 7:30 PM (GMT)


Where: Live Meeting

*~*~*~*~*~*~*~*~*~*

Tome Tanasovski MVP presents on Regular Expressions

Notes


Richard Siddaway has invited you to attend an online meeting using Live Meeting.
Join the meeting.
Audio Information
Computer Audio
To use computer audio, you need speakers and microphone, or a headset.
First Time Users:
To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
Troubleshooting
Unable to join the meeting? Follow these steps:

  1. Copy this address and paste it into your web browser:
    https://www.livemeeting.com/cc/usergroups/join
  2. Copy and paste the required information:
    Meeting ID: TRG55D
    Entry Code: Bd+;%:H8Z
    Location: https://www.livemeeting.com/cc/usergroups

If you still cannot enter the meeting, contact support

Notice
Microsoft Office Live Meeting can be used to record meetings. By participating in this meeting, you agree that your communications may be monitored or recorded at any time during the meeting.

PowerCLI book

Last May I posted a review of fellow PowerShell MVP Hal Rottenberg’s book on managing VMware through PowerShell - http://msmvps.com/blogs/richardsiddaway/archive/2010/05/09/book-review-managing-vmware-infrastructure-with-windows-powershell.aspx

My good friends from the UK PowerShell user group Jonathan Medd (also a PowerShell MVP) and Alan Renouf have collaborated with three other authors to bring you VMware vSphere PowerCLI Reference which is published at the end of March – ISBN 978-0470890790

I’ll be posting a review as soon as I can get hold of a copy

More details from http://www.jonathanmedd.net/2011/02/powercli-book-is-go.html#comments

Posted by RichardSiddaway | with no comments
Filed under:

PowerShell Deep Dive

If you haven’t seen it already check out the PowerShell Deep Dive at this years “The Experts Conference”. http://www.theexpertsconference.com/us/2011/general-information/2011-powershell-deep-dive/

As well as total immersion in PowerShell you can dabble in some of the minor technologies associated with it – AD, Exchange, SharePoint, Virtualisation and the cloud.

I’ll be there with a bunch of other PowerShell MVPs. Hope to see you there.

Posted by RichardSiddaway | 1 comment(s)
Filed under:

PowerShell and WMI–Chapter 5 MEAP

Chapter 5 has been released for PowerShell and WMI. It is available through the Manning Early Access Program (MEAP) at http://www.manning.com/siddaway2/
The available chapters cover:

  1. Solving Administrative Challenges
  2. Using PowerShell
  3. WMI in Depth
  4. Best Practices
  5. System Documentation


Chapters 6 to 8 covering Disk Systems, Registry and the file system respectively are in the pipeline. I’m currently working on chapter 9 on the processes and services. The code to accompany the MEAP chapters is also available for download from the URL above.

Posted by RichardSiddaway | with no comments

Performance monitoring with Get-Counter

I last looked at the Get-Counter cmdlet back in 2009 when we were in the middle of CTP 3 for PowerShell 2.  its time for a revisit.

Gathering performance counter information provides a good look inside your systems to enable you to decide what is going on. If you look at the Performance Monitor utility you will see that there are a great many counters we could use. if you want to see them try running this

Get-Counter -ListSet *

A better bet is to start looking at the sets of counters

Get-Counter -ListSet * | sort CounterSetName | select CounterSetName –Unique

When we are looking at performance monitoring the list of usual suspects is fairly small:

  • CPU
  • Memory
  • Disk
  • Networking

These four areas usually start to define problem areas.  We can expand to other areas later.

CPU is always top of the list to look at. On my Windows 7 system I have Processor and Processor Information counter sets. Lets see what’s in them

PS> Get-Counter -ListSet Processor  | select -ExpandProperty counter
\Processor(*)\% Processor Time
\Processor(*)\% User Time
\Processor(*)\% Privileged Time
\Processor(*)\Interrupts/sec
\Processor(*)\% DPC Time
\Processor(*)\% Interrupt Time
\Processor(*)\DPCs Queued/sec
\Processor(*)\DPC Rate
\Processor(*)\% Idle Time
\Processor(*)\% C1 Time
\Processor(*)\% C2 Time
\Processor(*)\% C3 Time
\Processor(*)\C1 Transitions/sec
\Processor(*)\C2 Transitions/sec
\Processor(*)\C3 Transitions/sec

 

PS> Get-Counter -ListSet "Processor Information" | select -ExpandProperty counter
\Processor Information(*)\Processor State Flags
\Processor Information(*)\% of Maximum Frequency
\Processor Information(*)\Processor Frequency
\Processor Information(*)\Parking Status
\Processor Information(*)\% Priority Time
\Processor Information(*)\C3 Transitions/sec
\Processor Information(*)\C2 Transitions/sec
\Processor Information(*)\C1 Transitions/sec
\Processor Information(*)\% C3 Time
\Processor Information(*)\% C2 Time
\Processor Information(*)\% C1 Time
\Processor Information(*)\% Idle Time
\Processor Information(*)\DPC Rate
\Processor Information(*)\DPCs Queued/sec
\Processor Information(*)\% Interrupt Time
\Processor Information(*)\% DPC Time
\Processor Information(*)\Interrupts/sec
\Processor Information(*)\% Privileged Time
\Processor Information(*)\% User Time
\Processor Information(*)\% Processor Time

 

These sets seem a bit similar.  We’ll start with the Processor counters. * means all instances.

if we look at the processor counters again

Get-Counter -ListSet Processor 

CounterSetName     : Processor
MachineName        : .
CounterSetType     : MultiInstance
Description        : The Processor performance object consists of counters that measure aspects of processor activity.
                     The processor is the part of the computer that performs arithmetic and logical computations, initi
                     ates operations on peripherals, and runs the threads of processes.  A computer can have multiple p
                     rocessors.  The processor object represents each processor as an instance of the object.
Paths              : {\Processor(*)\% Processor Time, \Processor(*)\% User Time, \Processor(*)\% Privileged Time, \Processor(*)\Interrupts/sec...}
PathsWithInstances : {\Processor(0)\% Processor Time, \Processor(1)\% Processor Time, \Processor(_Total)\% Processor Time, \Processor(0)\% User Time...}
Counter            : {\Processor(*)\% Processor Time, \Processor(*)\% User Time, \Processor(*)\% Privileged Time, \Proc essor(*)\Interrupts/sec...}

 

The Paths and PathsWithInstances properties of each performance counter set contain the individual counter paths formatted as a string. So lets look at them.

PS> Get-Counter -ListSet Processor | select -ExpandProperty Paths
\Processor(*)\% Processor Time
\Processor(*)\% User Time
\Processor(*)\% Privileged Time
\Processor(*)\Interrupts/sec
\Processor(*)\% DPC Time
\Processor(*)\% Interrupt Time
\Processor(*)\DPCs Queued/sec
\Processor(*)\DPC Rate
\Processor(*)\% Idle Time
\Processor(*)\% C1 Time
\Processor(*)\% C2 Time
\Processor(*)\% C3 Time
\Processor(*)\C1 Transitions/sec
\Processor(*)\C2 Transitions/sec
\Processor(*)\C3 Transitions/sec

 

PS> Get-Counter -ListSet Processor | select -ExpandProperty PathsWithInstances
\Processor(0)\% Processor Time
\Processor(1)\% Processor Time
\Processor(_Total)\% Processor Time
\Processor(0)\% User Time
\Processor(1)\% User Time
\Processor(_Total)\% User Time
\Processor(0)\% Privileged Time
\Processor(1)\% Privileged Time
\Processor(_Total)\% Privileged Time
\Processor(0)\Interrupts/sec
\Processor(1)\Interrupts/sec
\Processor(_Total)\Interrupts/sec
\Processor(0)\% DPC Time
\Processor(1)\% DPC Time
\Processor(_Total)\% DPC Time
\Processor(0)\% Interrupt Time
\Processor(1)\% Interrupt Time
\Processor(_Total)\% Interrupt Time
\Processor(0)\DPCs Queued/sec
\Processor(1)\DPCs Queued/sec
\Processor(_Total)\DPCs Queued/sec
\Processor(0)\DPC Rate
\Processor(1)\DPC Rate
\Processor(_Total)\DPC Rate
\Processor(0)\% Idle Time
\Processor(1)\% Idle Time
\Processor(_Total)\% Idle Time
\Processor(0)\% C1 Time
\Processor(1)\% C1 Time
\Processor(_Total)\% C1 Time
\Processor(0)\% C2 Time
\Processor(1)\% C2 Time
\Processor(_Total)\% C2 Time
\Processor(0)\% C3 Time
\Processor(1)\% C3 Time
\Processor(_Total)\% C3 Time
\Processor(0)\C1 Transitions/sec
\Processor(1)\C1 Transitions/sec
\Processor(_Total)\C1 Transitions/sec
\Processor(0)\C2 Transitions/sec
\Processor(1)\C2 Transitions/sec
\Processor(_Total)\C2 Transitions/sec
\Processor(0)\C3 Transitions/sec
\Processor(1)\C3 Transitions/sec
\Processor(_Total)\C3 Transitions/sec

 

These are the strings we need to use to collect performance information.

 

Get-Counter -Counter "\Processor(_Total)\% Processor Time" -MaxSamples 10

returns 10 samples 1 second apart showing the total processor usage

I have two cores in my system so I might want to see what the individual cores are doing

 

Get-Counter -Counter "\Processor(_Total)\% Processor Time", "\Processor(0)\% Processor Time", "\Processor(1)\% Processor Time" -MaxSamples 10

Next time we’ll look at memory

Posted by RichardSiddaway | with no comments
Filed under: ,

Windows 7 SP1

Installed the RTM version of SP1 today – its one download to cover Windows 7 and Windows 2008 R2.  Install is straight forward. No real issues seen.  I’ll report any problems that come up

Posted by RichardSiddaway | with no comments
Filed under:

More date oddities

I’ve mentioned before that if I do this

[datetime]"10/09/2011"

I get

09 October 2011 00:00:00

which is not what I expect as I live in the UK

 

Just been experimenting and discovered that

Get-Date "10/09/2011"

 

works correctly (for me) and returns

10 September 2011 00:00:00

 

It seems Get-Date picks up the locale and culture correctly but casting to [datetime] doesn’t.

Posted by RichardSiddaway | with no comments
Filed under:

IT lemmings

IT seems to be in a continuous cycle of hype. We keep getting “new” technologies or ways of supplying IT that will solve all of your organisations problems at a stroke. Some examples of this phenomenon include:

  • outsourcing – IT isn’t a core activity for you business so hand over the running of your IT systems to a specialist company who have the experts to deliver what you need and the economy of scale to do it cheaper
  • virtualisation – You don’t need lots of physical servers. Virtualise so that you are running a number of big servers really hard and they host a bunch of virtual servers that are doing the work
  • web services – everything will be available as a web service. Don’t write your own code just string together a set of pre-supplied services and nirvana is reached
  • cloud computing – move everything to Internet access. Let the supplier host the application and you just use it (How is this different from the failed Application Service Provider idea of the late 1990’s?)

Now before you start jumping up and down calling me a luddite let me point out that I am currently working in a environment that utilises three out of these four concepts. I am actively designing new services that employ two of them.

My concern is the misinformation and hype that surrounds “new” technologies. I keep calling it “new” because a number of these are recycled. I’ve already mentioned ASP/Cloud computing. I was working with “virtualisation” technologies on mainframes back in the 1980’s. What goes around comes around.

Each wave of “new” technologies brings a bubble of hype that is totally out of proportion to the benefits to be gained. The IT analyst companies start the ball rolling and the IT press (who usually don’t understand what they are talking about) jump on the bandwagon. Suddenly, the only way your organisation can survive is to throw away everything that has gone before and embrace this new way of doing things.

Reality Check

How many organisations have completely virtualised their environment. I have applications that can’t be virtualised because the vendor won’t support it in a virtual environment?

How many external web services does you company really use?

Can you run your organisation in the cloud? Many can’t because of regulatory or commercial restrictions that prevent it. This is often due to access to the data.

 

All of the ideas that are bandied about need consideration. Just because its new doesn’t mean that it suits your organisation.

This is where the good architect earns their money. Separate out what will benefit your organisation and utilise it. Ignore the rest. ignore the analysts and IT press telling you what you should be doing when they don’t have a clue what your organisation really needs.

There are organisations that will benefit from cloud computing. There are others that it will harm. Virtualisation is delivering benefits to the organisation I work with – but don’t forget the overheads that come with it.

One of my favourite phrases when discussing technology is “so what”.  Meaning what does it actually do for us? Does the benefit of implementing out weigh the cost?

This continual jumping towards the next shiny toy is why many businesses hold their IT departments in such low regard? The planning should always be from business process to applications to infrastructure to support them. Leading with technology doesn’t work and will continue to cost businesses money they possibly can’t afford.

Posted by RichardSiddaway | with no comments
Filed under:

Tonight’s Slides and recording

Thank you to everyone who attended tonight’s Live Meeting. Apologies for the sniffles, coughs and splutters but you were probably better off not being in the same room. Hopefully this cold will have gone before the next meeting.

As promised the here the URLs for the recording and the slides/demo scripts

Recording

Richard Siddaway has invited you to view a Microsoft Office Live Meeting recording.
View Recording
Recording Details
    Subject: Powershell utility cmdlets
    Recording URL: https://www.livemeeting.com/cc/usergroups/view
    Recording ID: 5D2B4R
    Attendee Key: h_>SF*D9q

 

Slides and demo scripts available at

http://cid-43cfa46a74cf3e96.office.live.com/browse.aspx/PowerShell%20User%20Group/February%202011

Last call

Last reminder for the UK PowerShell Group Live Meeting tomorrow night

http://msmvps.com/blogs/richardsiddaway/archive/2011/01/18/uk-user-group-february-live-meeting.aspx

 

Meeting in March will cover Regular Expressions with guest speaker Tome Tanasovski  MVP

Posted by RichardSiddaway | with no comments

PowerShell and WMI code

Manning are releasing the chapters of my latest book PowerShell and WMI under their Early Access Program. The first four chapters are available now from http://www.manning.com/siddaway2/.

The source code for these chapters has also been made available for download from the same site. As more chapters are released the source code will be released as well.

The code is raw & doesn’t have headers etc. It does (should) match the contents of the chapter.

Three more chapters are in the pipeline and will be released in the not too distant future

Enjoy

Posted by RichardSiddaway | with no comments

Thunderbirds

Do you remember the brilliant shows produced by Gerry Anderson:

  • Thunderbirds
  • Stingray
  • Captain Scarlet
  • Fireball XL5
  • Supercar

 

And even the not so brilliant Joe 90.

The Post Office (UK) is producing a set of stamps to commemorate the shows.  They are also providing wallpapers for you computer.  Download from https://treatbox.net/genius-of-gerry-anderson-wallpapers/?utm_source=eNewsletter&utm_term=2011-1&utm_medium=email&utm_campaign=GerryAndersonWallpapers

Enjoy

Posted by RichardSiddaway | with no comments

Don’t forget

The UK PowerShell group has a Live Meeting on Tuesday 8 February at 7.30pm GMT.

Details from:

http://msmvps.com/blogs/richardsiddaway/archive/2011/01/18/uk-user-group-february-live-meeting.aspx

Posted by RichardSiddaway | with no comments

COM pt 7–Items pt 2

In part 6 we looked at the drives collection on the FileSystemObject. The Items property was mentioned.

Lets jump back to our Shell object

$shell = New-Object -ComObject "Shell.Application"

 

if we do a Get-Member

$shell | gm

You will see a method called Namespace.  This allows you to work with the Special Folders. One such special folder contains the cookies on you system.

PS> $shell.Namespace(0x21)


Title                      : Cookies
Application                : System.__ComObject
Parent                     :
ParentFolder               : System.__ComObject
Self                       : System.__ComObject
OfflineStatus              :
HaveToShowWebViewBarricade : False
ShowWebViewBarricade       : False

 

If we look at the object

$shell.Namespace(0x21) | gm

 

we will find an Items method.

$shell.Namespace(0x21).Items()

 

will dump the information faster than you can read.  The Items method can not be used to dump individual items

 

We could do something like

$shell.Namespace(0x21).Items() | select Name, ModifyDate

 

if we want to see all of them.  This can be refined as

$shell.Namespace(0x21).Items() | sort ModifyDate -Descending | select Name, ModifyDate

To discover the number of cookies

($shell.Namespace(0x21).Items()).count

 

In many ways it is similar to the GetEnumerator method on hash tables

Posted by RichardSiddaway | with no comments
Filed under:

Online help

Its been a long day today so I’m going to skip the next part of the COM series and show a useful bit of functionality from a PowerShell cmdlet.

Anyone who has been around PowerShell for any length of time is aware of the get-help cmdlet e.g.

Get-Help Set-Content

get-help about_for

 

It is so fundamental to getting to know your way around PowerShell that I referred to it as one of your four best friends in PowerShell when I was writing PowerShell in Practice http://www.manning.com/siddaway/

What you might not be aware of is the –online parameter. This opens the help as posted on TechNet in your browser.

Get-Help Set-Content –Online

If you try this notice the date the online help was last updated  - April 21, 2010 at the time of writing. The PowerShell team will update the online content as documentation bugs are filed. If you see something in the help file that you don’t think is right try the online version to see if it has been changed.

What about our other example?

get-help about_for –Online

This generates an error

Get-Help : The online version of this Help topic cannot be displayed because there is no Uri for online Help in the "Related Links" section of the cmdlet Help topic.
At line:1 char:9
+ get-help <<<<  about_for -Online
    + CategoryInfo          : InvalidOperation: (:) [Get-Help], PSInvalidOperationException
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.GetHelpCommand

 

I’ve checked a random selection of about files and none of them had a URI. You can find them online at http://technet.microsoft.com/en-us/library/dd347616.aspx

Posted by RichardSiddaway | with no comments
Filed under:

Surprise

Life is full of surprises and one that has happened to me revolves around the post that seems to get the most attention.  Since moving to one of my mirrors from Microsoft Live to WordPress one of the extra features is a report on the post that gets the most traffic. Surprisingly it is this one from January 2008

http://richardspowershellblog.wordpress.com/2008/01/11/powershell-for-windows-server-backup/

I know that the PowerShell support for Windows backup has been changed in Windows 2008 R2 so I think I’d better do an update.  Look for it soon

Posted by RichardSiddaway | with no comments
Filed under:

COM pt 6–Collections pt 1

If we return to our filesystemobject

$fso = New-Object -ComObject "Scripting.FileSystemObject"

and look at the drives collection

$fso.Drives

 

we will see a collection of drives. If we try to index into it

$fso.Drives[0]

 

we get error that says
Unable to index into an object of type System.__ComObject.

 

can do something like this

$drives = $fso.Drives
foreach ($drive in $drives){$drive}

 

but still doesn’t allow us to reach individual drives

This is an issue with COM collections accessed in PowerShell. They do have a property called Item that we can use. Normally we would do something like

$fso.Drives.Item(1)

 

but we get an error about indexing.  If we look at the Item property

PS> $fso.Drives.Item


IsSettable          : False
IsGettable          : True
OverloadDefinitions : {IDrive Item (Variant)}
TypeNameOfValue     : System.Object
MemberType          : ParameterizedProperty
Value               : IDrive Item (Variant) {get}
Name                : Item
IsInstance          : True

 

It doesn’t want to take a number as an argument. It does take a drive letter

PS> $fso.Drives.Item("c")


Path           : C:
DriveLetter    : C
ShareName      :
DriveType      : 2
RootFolder     : System.__ComObject
AvailableSpace : 191890976768
FreeSpace      : 191890976768
TotalSize      : 249951154176
VolumeName     :
FileSystem     : NTFS
SerialNumber   : 941000572
IsReady        : True

 

If you know the drives then picking a letter is OK – otherwise we need to display everything as a first pass so we can work out what drives are mapped

Posted by RichardSiddaway | with no comments
Filed under: ,