July 2010 - Posts

Recording and slides for July 2010 UG meeting

This months meeting covered working with the registry.

The slides and the demo script are available from

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

 

The recording is available

Richard Siddaway has invited you to view a Microsoft Office Live Meeting recording.
View Recording
Recording Details
    Subject: PowerShell and the Registry
    Recording URL: https://www.livemeeting.com/cc/usergroups/view
    Recording ID: CB99JS
    Attendee Key: mm$2!",$G

Tomorrow – July UG meeting

Tomorrow is the PowerShell UG Live Meeting on the Registry, PowerShell, .NET and WMI.

Full details from

http://msmvps.com/blogs/richardsiddaway/archive/2010/07/20/july-2010-ug-meeting-registry.aspx

Posted by RichardSiddaway | with no comments

Complexity vs Heterogeneity

Most organisations have a degree of heterogeneity in their infrastructure for example:

  • mainly Windows with a few Unix or Linux servers
  • multiple versions of SQL Server because of application restrictions
  • a mixture of fat client and thin client systems because of application and mobility drivers
  • virtual and physical servers

Cost can also be a contributing factor to heterogeneity – for instance an organisation wants to virtualise its whole infrastructure but can’t afford to perform the migration in a single project under the current economic conditions.

Complexity, in infrastructure terms, may seem to be the same as heterogeneity in that a complex infrastructure is usually heterogeneous however a heterogeneous infrastructure isn’t necessarily complex.

Complexity arises from a number of sources:

  • multiple systems performing the same task
  • manual administration processes across multiple, disparate systems
  • multiple technologies - “just because we can”
  • wrong choice of technology
  • infrastructure driven by technology rather than business need
  • adopting new technologies without a clear business need

The last point may need some clarification.  There is a simple progression of needs:

  • organisations have business processes
  • business processes need applications to make them work
  • applications need to be hosted on and supported by infrastructure

If we approach this list in a top down manner we build infrastructure that meets the business requirements. If we supply technology and attempt to make the applications and business processes fit the result may well not meet the requirements and almost certainly will be more complex.

Complexity can be removed from a heterogeneous environment e.g:

  • use Active Directory for authentication\authorisation on your handful of Unix/Linux servers
  • extend your management tools across the whole environment
  • determine a strategic approach to infrastructure and ensure there is a governance/enforcement mechanism

I’ve stated before that infrastructure seems to a forgotten subject.  There is a lot published on software architectures but very little on the infrastructure.  We don’t even seem to have a set of guiding principles. I’ll offer one here:

Heterogeneity driven by business need should be embraced. Complexity should be removed from the environment.

Registry 7

One other aspect we need to cover is deleting individual values

001
002
003
$reg = [Microsoft.Win32.Registry]::LocalMachine
$key = $reg.OpenSubKey("Software\PSAM PSAdmins\Test", $true)
$key.DeleteValue("oops")

Open the key for writing and use the DeleteValue() method.

Posted by RichardSiddaway | with no comments
Filed under: , ,

Registry 6

Having created some keys lets add some values

001
002
003
004
005
006
007
008
009
010
011
$reg = [Microsoft.Win32.Registry]::LocalMachine
$key = $reg.OpenSubKey("Software\ITKE PSAdmins", $true)
$key.SetValue("Dword Entry", 567 ,"Dword") 
$key.SetValue("String Entry", "My new string" ,"String") 
$key.SetValue("Expanded String Entry", "%COMPUTERNAME%" ,"ExpandString")

[string[]]$multi = "Z","Y","X"
$key.SetValue("Multi-string Entry", $multi ,"MultiString")

$key = $reg.OpenSubKey("Software\PSAM PSAdmins\Test", $true)
$key.SetValue("Oops", "Didn't mean to do this" ,"String")

This is very similar to the script we used to change the values – open the key for writing and use SetValue().  Just make sure we use the right data type.
Posted by RichardSiddaway | with no comments
Filed under: , ,

Registry 5

Having seen how to read, change and delete keys – lets add some

 

001
002
003
$reg = [Microsoft.Win32.Registry]::LocalMachine
$key = $reg.CreateSubKey("Software\ITKE PSAdmins")
$key2 = $reg.CreateSubKey("Software\PSAM PSAdmins\Test")

Set the hive and call the CreateSubKey method.  Note the second example where we create a further depth of subkeys.  It isn’t necessary to create each step in the chain we can create the lot in one go

Posted by RichardSiddaway | with no comments
Filed under: , ,

Registry 4

Now is the time to delete a registry key

001
002
$reg = [Microsoft.Win32.Registry]::LocalMachine
$key = $reg.DeleteSubKey("Software\ITKE PSAdmins")

If there is a tree of subkeys then we can use the DeleteSubKeyTree() method

Posted by RichardSiddaway | with no comments
Filed under: , ,

Registry 3

Lets look at changing registry values. In http://msmvps.com/blogs/richardsiddaway/archive/2010/07/16/registry-1.aspx  I showed how to read the registry. We’ll change the 4 values we found in that post

001
002
003
004
005
006
007
008
$reg = [Microsoft.Win32.Registry]::LocalMachine
$key = $reg.OpenSubKey("Software\ITKE PSAdmins", $true)
$key.SetValue("Dword Entry", 567 ,"Dword") 
$key.SetValue("String Entry", "My new string" ,"String") 
$key.SetValue("Expanded String Entry", "%COMPUTERNAME%" ,"ExpandString")

[string[]]$multi = "Z","Y","X"
$key.SetValue("Multi-string Entry", $multi ,"MultiString")

 

Open the key as we did before except this time add a second parameter. $true indicates that the key is opened in a readable state. The SetValue method can be used to set the appropriate values. The parameters are the name of the value, the new value and the data type. Notice that for the multi-string value we supply and array of strings.

The acceptable data types are:

PS> Get-Enum Microsoft.Win32.RegistryValueKind
Unknown
String
ExpandString
Binary
DWord
MultiString
QWord

Posted by RichardSiddaway | with no comments
Filed under: , ,

July 2010 UG meeting - Registry

How we can use PowerShell, WMI and .NET to work with the registry

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: CB99JS
    Entry Code: mm$2!",$G
    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.

Registry 2

In the previous post I showed this line

$reg = [Microsoft.Win32.Registry]::LocalMachine

 

which we used to determine which registry hive we would work with.

LocalMachine is a member of the Microsoft.Win32.RegistryHive enumeration.

An enumeration is a closed list.

I’ve added this function to my profile

001
002
003
004
005
006
function Get-Enum {
param (
    [string]$class
)   
    [enum]::GetNames("$class")
}

so that I can quickly find the members of an enumeration.

Use it like this

PS> Get-Enum Microsoft.Win32.RegistryHive
ClassesRoot
CurrentUser
LocalMachine
Users
PerformanceData
CurrentConfig
DynData

Posted by RichardSiddaway | with no comments
Filed under: ,

Registry 1

In this http://itknowledgeexchange.techtarget.com/powershell/wmi-and-the-registry/ and subsequent posts I looked at using WMI to work with the Registry.  As part of a series examining .NET classes that are useful to admins I thought it would be interesting to look at the Registry first.

We start by linking to a registry hive in this case HKLM – the local machine hive

$reg = [Microsoft.Win32.Registry]::LocalMachine

 

We can then access a subkey.

$key = $reg.OpenSubKey("Software\ITKE PSAdmins")

 

This is the example key I created in the WMI series so you need to read that to see how I created it.

We can get the number of values

$key.ValueCount
4

Their names

$key.GetValueNames()
String Entry
Expanded String Entry
Dword Entry
Multi-string Entry

 

and their types

$key.GetValueNames() | foreach {"$_   $($key.GetValueKind($_))"}

String Entry   String
Expanded String Entry   ExpandString
Dword Entry   DWord
Multi-string Entry   MultiString

 

and the actual values

$key.GetValueNames() | foreach {"$_   $($key.GetValue($_))"}
String Entry   This is a string
Expanded String Entry   C:\Users\Richard\AppData\Local\Temp
Dword Entry   101
Multi-string Entry   A B C D

Book Review: Exchange Server 2010 Administrator’s Pocket Consultant

Author: William R. Stanek

Publisher: Microsoft Press

ISBN: 978-0-7356-2712-3

I recently reviewed the second edition of Windows Server 2008 R2 book in this series - http://msmvps.com/blogs/richardsiddaway/archive/2010/04/11/book-review-windows-server-2008-administrator-s-pocket-consultant.aspx.

As usual I am applying my three main criteria for judging a book:

· Is it technically accurate?

· Does deliver the material it claims to deliver?

· Is worth the cost of purchase and the time I spend reading it?

Like the Windows book this one comes in at over 600 pages – 664 to be precise. I’m not sure anymore who these books are aimed at but pocket sized they are no longer. I’ll return to the my thoughts on this series later.

The book is divided into 17 chapters:

1. Exchange Server 2010 Administration Overview

2. Deploying Exchange Server 2010

3. Exchange Server 2010 Administration Essentials

4. Using the Exchange Management Shell

5. User and Contact Administration

6. Mailbox Administration

7. Working with Distribution Groups and Address Lists

8. Implementing Exchange Server 2010 Security

9. Managing Data and Database Availability Groups

10. Mailbox and Public Folder Database administration

11. Accessing and Managing Public Folders

12. Managing Hub Transport and Edge Transport Servers

13. Managing Client Access Servers

14. Exchange Server 2010 Maintenance, Monitoring and Queing

15. Backup and Restoring Exchange Server 2010

16. Managing Exchange Server 2010 Clients

17. Managing Mobile Messaging users

The book sets out to “deliver ready answers for the day-to-day administration of Exchange Server 2010.” I want to focus this review on whether the book lives up to that ideal.

The book contains a lot of screen shots that nearly fill the page – due to the page size. There are also a lot of tables that aren’t really necessary. I also didn’t like the repetition when discussing the PowerShell commands - a syntax listing plus an example plus, in many cases, a full results listing seems to be more a way to drive up the page count than something that has actually been thought through.

There doesn’t seem to be any consistency in the way management task solutions are presented – some are GUI only, some are PowerShell and some are mixed. It would have been better to have a consistent method of approach. In some cases the PowerShell is badly written and does not encourage best practice. There is no consistency in the PowerShell presentation for example Format-List and fl are used but the fact the fl is an alias of Format-List is not mentioned. Potentially very confusing.

The content flips through discussing Exchange 2003, 2007 and 2010 without any real pattern. If the differences were presented this approach would be valuable otherwise it is confusing. There is a lot of repetition in the writing – was the editing rushed to meet a deadline?

The chapter order is sometimes strange – it would have made more sense to discuss databases before database availability groups for instance. The managing database copies would seem to fit better in the chapter on availability groups.

Overall the book seems to be unfocussed. The introduction mentions that Exchange Server 2010 Standard supports fewer databases than Enterprise but doesn’t make any further mention of the differences between the two versions.

When reviewing the Windows Server 2008 R2 Pocket Consultant I stated that it wasn’t clear who the book was aimed at. After reading this example of the series I would expand my statement and state that I think the series as a whole has lost sight of its goals. The books are too big to be pocket guides (even laptop bag pockets) but don’t carry enough detailed in depth information to be a real consultants book. The small page size makes them difficult to use on the desk when trying to keep the book open and type especially given the thickness to which these books have grown!

Given the price of these books I would tend to buy from the Administrator’s Companion series as they normally have a CD with an electronic version of the book. Now that’s portability.

If these books are to continue as a viable series I think they need to increase the technical content. At the moment they are hovering around the 100 level they need to be moving up to the 3-400 mark. The books also need to shrink in size to become true pocket consultants.

Judging against my criteria:

· Is it technically accurate? Not completely e.g. the confusion over Windows Server versions and the sloppy PowerShell code. I would give the book 7/10 for technical content. I’m reserving a few points because I think there is material that should be covered in greater depth.

· Does it deliver the material it claims to deliver? No I don’t think it does 5/10. I wouldn’t want my Exchange administrators to rely on this book.

· Is worth the cost of purchase and the time I spend reading it? Again I would say no and only award 5/10. The sloppy organisation and the amount of padding in the book don’t make it a worthwhile purchase in my view.

Overall I’d rate this as 5/10 and wouldn’t recommend it.

Posted by RichardSiddaway | with no comments
Filed under: ,

PowerShell in Practice Offer today

Manning are offering the print book for $25 today.  See www.manning.com and use code dotd0715cc

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

PowerShell User Group Next Meetings

Next meetings are:

27 July 7.30 BST – Registry, Transactions, Provider, WMI

14 September 8.30 BST – Jonathan Medd MVP on Remoting – Note the time change

Posted by RichardSiddaway | with no comments

Cookie Time

Needed to clear the cookies on my machine

$app = New-Object -ComObject Shell.Application

Get-ChildItem $app.namespace(0x21).Self.Path | Remove-Item

 

If you want to view them use

Get-ChildItem $app.namespace(0x21).Self.Path | sort lastwritetime –Descending

instead

Posted by RichardSiddaway | with no comments
Filed under:

Netbook revisited

I’ve had the HP mini 210 netbook for just over a month now. It is working out really well. 

I’ve written quite a bit on it – the relatively small height of the screen would be a problem for formatting large chunks of text and seeing the results but for first draft writing its great. Especially on the move.

I was unsure about just having 1GB of RAM but the machine seems perfectly responsive for what I’m doing – better than some of the laptops I’ve had to use.

The touchpad is still giving me a few problems but as I never get on with touch pads that’s not a surprise. My blue tooth mouse works just fine when I need a lot of mouse work.

Internet browsing is OK – again the relatively small screen size is a little restrictive.  I did use it on my last user group webcast as a monitor so I could see what was actually going out.  Worked a treat for that.

The other use I intended for was to run ebook readers – that works excellently.

Battery life is at least 6 hours and can be more depending on activities.

All in all it was a good investment.

Next purchase though is a beast of machine for using as a demo machine with Hyper-V and lots and lots of RAM

Posted by RichardSiddaway | with no comments
Filed under: ,

PowerShell and Visio: Opening a file 3

We have seen how to open a file and add the stencil that goes with it.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
$visio = New-Object -ComObject Visio.Application
$doc = $visio.Documents.Open("C:\Scripts\Visio\adtest.vsd")

## set active page
$pages = $visio.ActiveDocument.Pages
$page = $pages.Item(1)

## Add a stencil
$mysten = "C:\Program Files\Microsoft Office\Office14\Visio Content\1033\ADO_M.vss"
$stencil = $visio.Documents.Add($mysten)

$page.Shapes | Format-Table Name, Text, Id, Index -a

## create variables
foreach ($shape in $page.Shapes) {
    if ($shape.Name -like "Directory connector*") {
        New-Variable -Name $($Shape.Name) -Value $shape -Force
    }
    else {
        New-Variable -Name $($Shape.Text) -Value $shape -Force
    }
}

In this version we extend the script to display information about the shapes

Name                    Text       ID Index
----                    ----       -- -----
Domain                  manticore   1     1
Organizational unit     England    47     2
Directory connector                57     3
Organizational unit.58  Yorkshire  58     4
Directory connector.68             68     5
Organizational unit.69  York       69     6
Directory connector.79             79     7
Organizational unit.80  London     80     8
Directory connector.90             90     9
Organizational unit.91  Scotland   91    10
Directory connector.101           101    11
Organizational unit.102 Wales     102    12
Directory connector.112           112    13
Organizational unit.113 Ireland   113    14
Directory connector.123           123    15
Organizational unit.124 Portugal  124    16
Directory connector.134           134    17
Organizational unit.135 Lisbon    135    18
Directory connector.145           145    19
Organizational unit.146 Belgium   146    20
Directory connector.156           156    21
Organizational unit.157 Latvia    157    22
Directory connector.167           167    23

 

and then to create a variable for each shape.  Now we can start to manipulate the objects

PowerShell and Visio: Opening a file 2

If you run the AD diagramming script we looked at recently and save the Vision drawing on problem is that the stencil doesn’t open with it. We have to go back and add it

001
002
003
004
005
006
007
008
009
010
$visio = New-Object -ComObject Visio.Application
$doc = $visio.Documents.Open("C:\Scripts\Visio\adtest.vsd")

## set active page
$pages = $visio.ActiveDocument.Pages
$page = $pages.Item(1)

## Add a stencil
$mysten = "C:\Program Files\Microsoft Office\Office14\Visio Content\1033\ADO_M.vss"
$stencil = $visio.Documents.Add($mysten)

That enables us to start working on the document manually but can we discover the objects in the drawing?

PowerShell and Visio – Opening a file

If all you want to do is open a Visio drawing then the simplest way is to use

Start-Process test.vsd

This will open the file in Visio ready for you to start work on it.

If you want to open the file and work on it programmatically then we have a little bit more to do.

001
002
$visio = New-Object -ComObject Visio.Application
$doc = $visio.Documents.Open("C:\Scripts\Visio\test.vsd")

Now we have our drawing we can start to do stuff with it