Thursday 16 April 2009

This blog has moved

I decided it was about time to smarten up my blog so from now on you should check out http://jonathanmedd.net . I transferred the feed so anyone subscribed to http://feeds2.feedburner.com/JonathanMedd will automatically get the new content.

Thanks for staying with me :-)

Tuesday 7 April 2009

Putting Shay's Powershell Registry Functions To Use

Recently I needed to check some registry key values on a bunch of servers. There were far too many servers to make this a manual task and in addition if they weren't what I was expecting then I needed to change them.

Shay Levy has very helpfully published a Stand Alone Registry Functions Library which I made use of. It allows you to query and set registry values for things such as DWords, Strings, Binary Values on remote machines very easily. In my case I was particularly interested in some configuration settings for the ICA protocol, HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\ICA-tcp, all of them DWords.

First of all we use Shay's Get-RegDWord function at the top of the script which contains some .NET code to query a remote registry


function Get-RegDWord{
param(
[
string]$server = ".",
[
string]$hive,
[
string]$keyName,
[
string]$valueName,
[
object]$defaultValue="Your default value"
)

$hives = [enum]::getnames([Microsoft.Win32.RegistryHive])

if($hives -notcontains $hive){
write-error "Invalid hive value";
return;
}
$regHive = [Microsoft.Win32.RegistryHive]$hive;
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($regHive,$server);
$subKey = $regKey.OpenSubKey($keyName);

if(!$subKey){
write-error "The specified registry key does not exist.";
return;
}
$subKey.GetValue($valueName,$defaultValue);
}
Then we specify the list of servers to query. You could either use something like:

$servers = Get-Content servers.txt
or in my case they were all virtual servers in VMware so I used a couple of VI Toolkit commands to specify the list

# Connect to Virtual Center
Connect-VIServer vc

# Get a list of all the powered on APP servers
$servers = Get-Folder 'Servers' | Get-VM | Where-Object {$_.Powerstate -eq 'PoweredOn'}

Then we loop through each server, call Shay's Get-RegDWord function for each of the DWords we are interested in and store the results in the $myCOl variable. At the end we export the $myCol variable into a CSV file for handy viewing.

# Create an empty array to store the results in
$myCol = @()

foreach ($server in $servers){

$hive = 'LocalMachine'
$keyname = 'System\CurrentControlSet\Control\Terminal Server\WinStations\ICA-tcp'

# Find MaxIdleTime
$valuename = 'MaxIdleTime'
$MaxIdleTime = Get-RegDWord $server $hive $keyName $valueName

# Find fInheritMaxIdleTime
$valueName = 'fInheritMaxIdleTime'
$fInheritMaxIdleTime = Get-RegDWord $server $hive $keyName $valueName

# Find MaxDisconnectionTime
$valueName = 'MaxDisconnectionTime'
$MaxDisconnectionTime = Get-RegDWord $server $hive $keyName $valueName

# Find fInheritMaxDisconnectionTime
$valueName = 'fInheritMaxDisconnectionTime'
$fInheritMaxDisconnectionTime = Get-RegDWord $server $hive $keyName $valueName

# Add the results to the $MYInfo variable, then $myCol
$MYInfo = "" | select-Object Name,MaxIdleTime,fInheritMaxIdleTime,MaxDisconnectionTime,fInheritMaxDisconnectionTime
$MYInfo.Name = $server
$MYInfo.MaxIdleTime = $MaxIdleTime
$MYInfo.fInheritMaxIdleTime = $fInheritMaxIdleTime
$MYInfo.MaxDisconnectionTime = $MaxDisconnectionTime
$MYInfo.fInheritMaxDisconnectionTime = $fInheritMaxDisconnectionTime
$myCol += $MYInfo

}

# Export the results to a csv file
$myCol | Export-Csv citrixservers.csv -NoTypeInformation

Now that we can view the results I was able to see that I needed to set a lot of these values to something new. Using Shay's Set-RegDWord function it is a pretty straightfoward task to extend the above to do that. First of all add the function to the top of the script.


function Set-RegDWord{
param(
[
string]$server = ".",
[
string]$hive,
[
string]$keyName,
[
string]$valueName,
[
double]$value
)

$hives = [enum]::getnames([Microsoft.Win32.RegistryHive])

if($hives -notcontains $hive){
write-error "Invalid hive value";
return;
}
$regHive = [Microsoft.Win32.RegistryHive]$hive;
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($regHive,$server);
$subKey = $regKey.OpenSubKey($keyName,$true);

if(!$subKey){
write-error "The specified registry key does not exist.";
return;
}
$subKey.SetValue($valueName, $value,[Microsoft.Win32.RegistryValueKind]::DWord);
if($?) {$true} else {$false}
}

Then for each of the values you want to change use an if statement to check whether it needs changing and if so call Shay's Set-RegDword to make the necessary changes.



    # Find fInheritMaxIdleTime
$valueName = 'fInheritMaxIdleTime'
$fInheritMaxIdleTime = Get-RegDWord $server $hive $keyName $valueName

# Check the value and change if necessary
if ($fInheritMaxIdleTime -eq 1){

$value = '0'
Set-RegDWord $server $hive $keyName $valueName $value

}

Thanks again to Shay for publishing these functions, it made this particular task very easy to complete and I'm sure I'll be using them again in the future.

Thursday 12 March 2009

Get-Scripting Guys Take Over the March UK Powershell User Group

Myself and Alan Renouf from the Get-Scripting Podcast will be presenting this month at the UK Powershell User Group on Thursday 26th March at Microsoft in Reading.

First up on the night will be Richard Siddaway talking to us about using Regular Expressions in Powershell. This was requested at a previous event and I know that Richard is really looking forward to talking about that subject ;-)

Then the Get-Scripting guys will take over:

I will be talking about some of the features that are part of Active Directory in Server 2008 R2 , currently in beta, in particular the native AD Powershell cmdlets which will ship as part of that product and what I have learned about them so far.

vExpert Alan Renouf will then tell us about the VI toolkit, which for those of you not in the know are the cmdlets shipped by VMware to enable you to manage their ESX product.

A good mixture I think of general scripting skills, third-party added value to your Powershell learning and future technologies.

If you can't make the event in person then as usual it will be broadcast by LiveMeeting (details here). It wouldn't be a UK Powershell event if the LiveMeeting part doesn't go 100% to plan, but we will endeavour to ensure we avoid the usual trick of the microphone going on mute.

If you wish to attend the event in person you should contact Richard via his blog so that he can have a badge for you at the welcome desk. If the prospect of us presenting isn't enough to attract you then as always there will be pizza at half-time :-)

Tuesday 10 March 2009

Today's UK VMware User Group

Today's UK VMware User Group was a great community content event. Of course there was a sponsor presentation (Veeam) without whom these type of events can't be put on, but there were also a lot of contributions from people in the group.

We had:

1) Veeam talking about their reporting and backup products.

2) Mike Laverick from RTFM education talking about Site Recovery Manager and not the VMware view of it, rather real world struggles - warts and all as he put it. Its great to see this kind of content because you get to find out how these products really function in reality. He also gave away a few copies of his book on Site Recovery Manager which I'm sure is a must read for this topic.

3) Get-Scripting's very own vExpert Alan Renouf gave us a debrief from VMworld Europe in Cannes. By the sounds of it a great event, but possibly could be extended to include an extra day and maybe needs a bigger venue given the issues some people had getting into sessions.

4) A presentation from another community member about technology futures, 'the cloud', advances in mobile devices, stuff like that, and how they may affect the corporate world. This is now the second event I have been to which has talked about employee owned IT, i.e. you turn up to a job with your own laptop and corporate IT supply you either with a VM to run corporate applications or all delivered through a browser. The demand coming from cool, young, hip people (like me :-) ) who won't stand for the constraints of a corporate environment.

"Why can't I run facebook / second life / quake / twitter on my macbook / ipod/ pink netbook and just run your apps on the same machine too?"

5) Steve Bruck and Alan Renouf (again) with an update about the recently released VI toolkit V1.5 . Some good examples, also lots of interest in Alan's getting started guide.

6) Finally finished off with more community content, this time about the upcoming vCenter Heartbeat product.


It was great to see slightly more audience participation than normal this time, which I think might have come from the slightly smaller room and more, but shorter sessions. I really enjoyed it anyway.

If you want to hear REAL people talking about how they really use VMware based products then this is the event for you.

Next one 14th May! More details can be found here.

Wednesday 4 March 2009

Counting the Number of Sessions Per Citrix Server

Whilst monitoring some newly provisioned Citrix servers running on VMware hosts today, I soon became very bored with manually checking how many sessions were on each Citrix VM as the load on each one increased, whilst trying to get it to the optimum level.

I knew it was possible to use Powershell to connect with Citrix servers, but had never really looked into it before. Not surprisingly it turned out to be very straightforward.

By using some technology known as MFCom we can connect with the Citrix farm and get some cool information out.

In the below example we create a new com object using MFCom, then initialise the connection. We are then able to access some methods and properties of that object. In this case we are looking at the Sessions property, we group all of the results by ServerName and then produce some output with the name and number of sessions on that Citrix box.

$farm = New-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize(1)
$farm.Sessions | Group-Object ServerName | Sort-Object name | Format-Table Name,Count -auto
which will give you something like:

Name Count

CitrixServer01 38
CitrixServer02 45
CitrixServer03 41

This would return all of the servers in the farm. In this particular instance I only wanted a particular selection of servers, so I stored them in a text file, got PS to read that file and then filter the query by only looking at servers in that list.


$servers = Get-Content c:\scripts\servers.txt

$farm = New-Object -com "MetaframeCOM.MetaframeFarm"
$farm.Initialize(1)
$farm.sessions | Where-Object {$servers -contains $_.ServerName} | Group-Object ServerName | Sort-Object name | Format-Table Name,Count -auto

Once again Powershell very easily gets rid of a really dull manual task.

If you wish to take this a step further check out Powershell MVP Brandon Shell's blog where he has loads of Powershell / Citrix examples.

http://bsonposh.com/archives/tag/citrix

Sunday 22 February 2009

UK Active Directory User Group - 6pm GMT Wednesday 11th March

This is the second meeting of the newly formed UK Active Directory User Group:

The second [ADUG] UK Active Directory User Group meeting will be on the evening of the 11th March at Microsoft's London (Victoria) Offices. The meeting will co-hosted with the Windows Server User Group.

The draft agenda is:
  • 18:00 for 18:25 Arrival and registration
  • 18:25-18:30 Welcome and introductions
  • 18:30-19:45 James O'Neill takes a quick tour through the new features in Windows Server 2008 R2 (just to whet your appetite).
  • 19:45-20:00 Refreshments
  • 20:00-21:15 Amish Lukka (also from Microsoft) will be presenting an insight into new Active Directory features in Windows Server 2008 R2.
  • 21:15-21:30 Wrap-up.
  • 21:20 Adjourn to a nearby public house where Mark Parris will be happy to share his experiences of the Microsoft Certified Masters: Windows Server 2008: Directory class that he attended last November.

If you are interested in attending - please send an email to registration@adug.co.uk with your name and see you there. The confirmed times will be in the confirmation email.


For those who can’t make it in person, we will set up a Live Meeting session (which will be recorded) and details will be made available closer to the event.

UK London VMware User Group Meeting, Tuesday 10th March 2009

These are great events if you are able to get to them (unfortunately no webcast for this one):

The Steering Committee are pleased to announce the next UK London VMware User
Group meeting, now kindly sponsored by Veeam Software, to be held
on Tuesday 10th March 2009. We hope to see you at the meeting, and
afterwards for a drink or two.

Our meeting will be held at the Thames Suite, London Chamber of Commerce and
Industry, 33 Queen Street, London EC4R 1AP, +44 (0)20 7248 4444. The nearest
tube station is Mansion House, location information is available here.

PLEASE NOTE: As well as the date changing from the previously-published one, the day
has also changed to Tuesday, and we're in a different part of the venue
from normal (out of the lift, turn right). Rest assured, the usual UG
staples of great content and me banging on about Powershell will be
present and correct.

Reception is from 1230 for a prompt 1pm start, to finish around 5pm. Our agenda
for is not final at the moment, but looks something like this:

12:30 – 13:00 Arrive & Refreshments
13:00 – 13:15 Welcome & News
13:20 – 14:05 Sponsor Presentation - TBA
14:10 – 14:55 Presentation on real world Site Recovery Manager experience
15:00 – 15:20 Refreshments Break
15:25 – 16:00 Committee-moderated, user-generated content and discussion (some good stuff being lined up here)
16:05 – 16:45 VMworld Cannes debrief
16:45 – 17:00 Close
17:00 – Pub

Please feel free to contribute to the 'UG content ideas' forum thread running here. We won't be able
to incorporate all of the ideas for this coming meeting, but will do our best
to include some of them.

To register your interest in attending, please reply with up to two named
attendees from your organisation to alaricdavies at yahoo dot com. If you do not receive a confirmation mail
from us, please don't just turn up since we will not be able to admit you to
the meeting. Content from the meetings will continue to be uploaded to http://public.box.net/londonug,
NDA permitting.

Sincerely, and with regards,

The UKLVMUG Steering Committee