Monthly Archives: July 2010

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

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.

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.

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

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

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

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