July 2008 - Posts

Subject swap

Due to unforeseen circumstances we have had to swap the subject of tonight's User Group Live Meeting.  I'm doing a session on administering IIS 7 from PowerShell showing and contrasting the various options.  Marco's session on the net cmdlets is postponed until next month

 

Share this post :

 

Technorati Tags: ,

UK PowerShell User Group Live Meeting

Date: 31 July  2008

Time: 7pm BST (GMT+1)

Marco Shaw, PowerShell MVP will be talking about /n software netcmdlets

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: JQ5754
    Entry Code: 6M+7p&KhN
    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.

 

Share this post :

 

Technorati Tags: ,

PowerShell Event Registration Open

There will be a TechNet PowerShell event in Birmingham (UK) on the afternoon of 14 October 2008.  Registration is open at http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032383908&Culture=en-GB

 

Share this post :

 

Technorati Tags:

Posted by Richard Siddaway's Blog
Filed under:

Blog Mirror

This blog is now mirrored on http://msmvps.com/blogs/RichardSiddaway/Default.aspx  Evidently spaces.live.com is blocked by some firewalls so the blogs cannot be accessed.  msmvps.com should be accessible.

 

 

 

Technorati Tags: ,

Posted by Richard Siddaway's Blog
Filed under:

PowerGUI - intellisense

One nice touch I found with the PowerGUI editor recently - if you start to type a path in the filesystem there is an intellisense popup to enable you to select the folder and subfolders.  Very useful and saves typing and mistakes.  Not sure when this feature first appeared but it is good.

 

Share this post :

 

Technorati Tags:

Posted by Richard Siddaway's Blog
Filed under:

PowerShell Event

There will be a TechNet PowerShell event in Birmingham (UK) on the afternoon of 14 October 2008. Registration details will follow next week when they are available.

If there is sufficient interest we will look at running a PowerShell User Group event afterwards

 

Share this post :

 

Technorati Tags:

Posted by Richard Siddaway's Blog
Filed under:

PowerGUI 1.5.1 RTM

PowerGUI has released version 1.5.1  - download from http://www.powergui.org/downloads.jspa

Details from http://dmitrysotnikov.wordpress.com/2008/07/25/powergui-151-rtms/

 

Share this post :

 

Technorati Tags:

Posted by Richard Siddaway's Blog
Filed under:

String expansion

One of the nice features of PowerShell is string expansion.  Put a variable in the middle of a double quoted string (single quoted strings take the contents literally and don't expand) and the variable is substituted into the string when it is evaluate.

Example

PS> $a = "a"
PS> $b = "b"
PS> $c = "c"

PS> "$a"
a

PS> "$a$b$c"
abc

Define three string variables as shown and then try substituting them into the string.  It works as shown. This seems to break down when an underscore character gets involved.

PS> "$a_"

PS> "$a$b"
ab
PS> "$a$b_"
a
PS> "$a_$b"
b
PS> "_$a$b"
_ab
PS> "_$a$b$c"
_abc
PS> "$a_$b$c"
bc
PS> "$a$b_$c"
ac
PS> "$a$b$c_"
ab
PS> "_$a$b$c"
_abc

Put the underscore character after the variable and the variable is ignored. Put it before a variable and it works.

Use an escape character

PS> "$a`_$b"
a_b
PS>

and it works.

So the underscore character has the effect of nullifying a variable.  I've not seen this before and if anyone has an explanation I'd love to hear it.  I've not been able to find an explanation by checking out the usual sources. Maybe I'm missing something here but in the mean time be careful when using _ characters like this.

 

Share this post :

 

Technorati Tags:

Posted by Richard Siddaway's Blog
Filed under:

User Group Meeting - New Date

Apologies but we need to move the Live Meeting hosted by the UK PowerShell User group to 31 July.

Marco Shaw, PowerShell MVP, will be talking about /n software NetCmdlets

Webcast will be 1 hour starting at 7pm UK time (GMT+1)

If you are not a member of the user group leave me a comment with contact  details or email me at powershell-uk {At} hotmail [dot] co (dot) uk

 

Share this post :

 

Technorati Tags: ,

WMI Classes

In this post http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!1525.entry I talked about the difference between Get-WmiObject and [WmiClass].  I've had a comment left asking "But how do you know that there is Win32_Process inside this class?!?!?"

This question could have several meanings.  What I did in the post was a bit of a circular argument as I started with Win32_Process deliberately - mainly because it and notepad should be available to everyone working with PowerShell.  So I know that the class is Win32_Process because thats how I set it up to be.

WMI classes are not the same as .NET classes.  WMI is COM based. We can access it through the System.Management.xxxx  .NET classes which is what we are working with when we use the PowerShell WMI commands.

In the wider context how do I know that windows processes are represented by Win32_Process. Partly its experience - I've been working with Windows and WMI for a long time.  How long did you ask?  Hmmmm, I could tell you but...........

The other way to discover what the WMI classes represent is to dig into them.

Get-WmiObject -List

will give you a list of WMI classes in the cimv2 namespace which is where most of the common Windows admin WMI classes sit.  The names are often self describing. Have a try of them with Get-WmiObject - its read only so you won't damage your system.

Other methods include:

- use wmiexplorer from http://thepowershellguy.com/blogs/posh/archive/2007/03/22/powershell-wmi-explorer-part-1.aspx

- PowerShell scriptomatic from http://www.microsoft.com/technet/scriptcenter/tools/psomatic.mspx

- WMI Reference information from http://msdn.microsoft.com/en-us/library/aa394572.aspx

Hope this helps

 

Share this post :

 

Technorati Tags: ,

Sorting a hash table

There is a really good PowerShell script for working with indexed files - scans or photos and renumbering to cope with missing numbers available from http://www.tellingmachine.com/post/2008/07/Renaming-a-series-of-indexed-files-with-Powershell.aspx

One point at the end of the post is about sorting hash tables.  This is not intuitive as piping the hash table into sort does not work.  You need to use the GetEnumerator() before trying to sort like this

PS> $a = @{}
PS> $a[[int]1] = "dir scan0001.txt"
PS> $a[[int]11] = "dir scan0011.txt"
PS> $a[[int]3] = "dir scan0003.txt"
PS> $a

Name                           Value
----                           -----
3                              dir scan0003.txt
1                              dir scan0001.txt
11                             dir scan0011.txt

PS> $a.getEnumerator() | Sort Key -Descending

Name                           Value
----                           -----
11                             dir scan0011.txt
3                              dir scan0003.txt
1                              dir scan0001.txt

PS> $a.getEnumerator() | Sort Name -Descending

Name                           Value
----                           -----
11                             dir scan0011.txt
3                              dir scan0003.txt
1                              dir scan0001.txt

Create a hash table as shown.  Use the getEnumerator() method and pipe into sort.  Sorted!

 

Share this post :

 

Technorati Tags:

Posted by Richard Siddaway's Blog
Filed under:

UK User group meeting

There will be a Live Meeting hosted by the UK PowerShell User group on 29 July.

Marco Shaw, PowerShell MVP, will be talking about /n software NetCmdlets

Webcast will be 1 hour starting at 7pm UK time (GMT+1)

If you are not a member of the user group leave me a comment with contact  details or email me at powershell-uk {At} hotmail [dot] co (dot) uk

 

Share this post :

 

Technorati Tags: ,

PowerShell labcast

There is a PowerShell labcast available from

https://www.microsoft.com/resources/virtuallabs/step1-technet.aspx?LabId=f7c0553e-78ee-4514-a9aa-097b673be3a7

Some one who tried it reports:

"It has a few quirks – on one occasion the voice-over disappears for a few minutes. If you leave the labcast and return to it later, your VM (and your work) is gone, so best done in a single session – or do the labwork on your local machine. Exposure to other scripting tools will help – most of the concepts transfer."

 

Share this post :

 

Technorati Tags:

Posted by Richard Siddaway's Blog
Filed under:

Remove-WmiObject

Having shown how a new WMI object can be created using Invoke-WmiMethod we need to consider how to remove a WMI Object.  CTP 2 supplies a Remove-WMIObject cmdlet.  This takes a WMI path to identify the individual object or you can use Get-WMIObject to identify object and pipe the result to Remove-WMIObject

Get-WmiObject -Class Win32_process -Filter "Name='notepad.exe'" | Remove-WmiObject

Remove-WMIObject does not support the -whatif and -confirm parameters so best practice is to use get-wmiobject and the filter capability to identify the correct object before piping to Remove-WMIObject

 

Share this post :

 

Technorati Tags: ,

Invoke-WmiMethod

In this post http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!1525.entry I showed how to use the [WMIClass] accelerator to create a new WMI Object - in this case a process running notepad.

CTP2 streamlines the process to a degree in that the Invoke-WmiMethod can do it all in one line

Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "notepad.exe"

Straight forward single cmdlet that does the job.  Very easy.

 

Share this post :

 

Technorati Tags: ,

 

PowerShell and SQL Server

Michiel Wories provides a look at some of the thinking behind PowerShell in SQL Server and future plans  - http://blogs.msdn.com/mwories/archive/2008/06/25/what-no-cmdlets-sql-server-powershell.aspx

 

Share this post :

 

Technorati Tags: ,

And now Hamlet

Dmitry has risen to the challenge with a PowerShell version of Hamlet - http://dmitrysotnikov.wordpress.com/2008/07/14/powershell-hamlet/

 

Share this post :

 

Technorati Tags:

Posted by Richard Siddaway's Blog
Filed under:

IIS PowerShell CTP 2 Live Meeting

The IIS Team have announce a Live Meeting to discuss IIS 7 PowerShell provider CTP2

Details from http://forums.iis.net/t/1150349.aspx

 

Share this post :

 

Technorati Tags: ,

Posted by Richard Siddaway's Blog
Filed under:

[WMI]

There is one last WMI accelerator to look at - [WMI] - which is an accelerator for System.Management.ManagementObject.  This is the same object type that Get-WMIObject returns. [WMI] gets an object representing an existing WMI object

If we start with Get-WmiObject

$w1 = Get-WmiObject -Class Win32_Process -Filter "Name = 'notepad.exe'"
$w1 | get-member

If we try to emulate this with [WMI] we start to run into some issues.  The only path that I could get to work was

$w2 = [WMI]'root\cimv2:Win32_Process.Handle="4112"'
$w2 | get-member

I tried name, description and other candidates but none seemed to work.  Only thing I can think of is that to create that PowerShell is constraining the object creation.

Alternatively the object could be created like this

$y = [WMI]""
$y
$y.psbase.Path = '\\PCRS2\root\cimv2:Win32_Process.Handle="4112"'

Comparing the results of these three techniques we get

Compare-Object -ReferenceObject $w1 -DifferenceObject $w2
Compare-Object -ReferenceObject $w1 -DifferenceObject $y

Both of which indicate the objects are the same.

Looking at creating this with .NET

$z = New-Object -TypeName System.Management.ManagementObject -ArgumentList '\\.\root\cimv2:Win32_Process.Handle="4112"'
$z | Get-Member

Compare-Object -ReferenceObject $w1 -DifferenceObject $z

Again the same object is created and I could only get it to build when I use the handle.

The object creation works when I do

$t = Get-WmiObject -Class Win32_process -Filter 'name="notepad.exe"'

As we need to know the path before we can use [WMI] it may be easier to use get-WmiObject instead.  I'd be interested in hearing other peoples take on [WMI] and how they are using it

 

Share this post :

 

Technorati Tags: ,
More Posts Next page »