Monthly Archive

Categories

Windows Server 2008 R2

Network Connection Ids

Yesterday I was looking at changing a Network connection id (the name that shows in Network and Sharing Center when you look at the adapters). I kept getting an error – either COM or number of arguments depending if I was running locally or remotely.

I eventually realised that I must be using a connection id that already existed in the Registry.  I tracked them down to

HKLM:\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}

This works for Windows 7 and Windows 2008 R2. Please check for other Windows versions.

This produces a bunch of subkeys of the form

{F913D3B9-DBE4-455C-8926-10E24AB4E68A}

Each of these has a subkey Connection with a value of Name that we are interested in

function get-Registryconnectionid{             
[CmdletBinding()]             
param (             
   [string]$computer="."             
)             
BEGIN{}#begin             
PROCESS{            
            
Write-Verbose "Reading registry keys for IDs"            
$HKLM = 2147483650            
$key = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"            
$reg = [wmiclass]'\\.\root\default:StdRegprov'            
$subkeys = $reg.EnumKey($HKLM, $key)            
            
            
foreach ($name in $subkeys.snames){            
  if ($name -eq "Descriptions"){Continue}            
  $conkey = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\$name\Connection"            
  Write-Debug $conkey            
              
  $cvalue = "Name"            
  $id = $reg.GetStringValue($HKLM, $conkey, $cvalue)  ## REG_SZ            
              
  $ivalue = "DefaultNameIndex"            
  $index = $reg.GetDwordValue($HKLM, $conkey, $ivalue)  ## REG_DWORD            
  $connection = New-Object -TypeName PSObject -Property @{            
       Index = $index.uValue            
       Connection = $id.sValue            
    }            
  $connection              
}            
            
            
}#process             
END{}#end            
            
<# 
.SYNOPSIS
Retrieves network connection ids 

.DESCRIPTION
Retrieves network connection ids held in the registry.
This includes current and previous ids.

.PARAMETER  Computer
Computer name

.EXAMPLE
get-Registryconnectionid

.EXAMPLE
get-Registryconnectionid -computer server02

#>            
            
}

This uses the standard WMI methods to read a local or remote registry

The corresponding current values are given by

Get-WmiObject -Class Win32_NetworkAdapter | select NetConnectionId, Index

The two index values are not related

Networking pains

Last week my wireless router decided that it had enough and wasn’t going to work any more. This was annoying because I was due to give a user group presentation that night.

I got a new router up and working but today discovered that connectivity from my Hyper-V environment wasn’t working. With the previous router I’d configured bridging between a Hyper-V virtual network and the wireless adapter in my host. That had to be recreated at which point I discovered that the new router didn’t want to support bridging.

I ended up using RRAS and NAT to get the connectivity. The instructions I found here

http://sqlblog.com/blogs/john_paul_cook/archive/2008/03/23/using-wireless-with-hyper-v.aspx

provide most of what you need.

Remember to set the default gateways and DNS servers properly for it all to work.

Active Directory snapshots I

One of the useful, but often overlooked, features of Windows 2008 & 200 R2 is the ability to take snapshots of your AD database.  These can be then mounted and accessed in parallel with your live AD.  Its possible to compare before and after so you can see what changes have been made. In Windows 2008 they can also be used to populate re-animated tombstone objects (in Windows 2008 R2 we’d just recover from the recycle bin).

More information cam be found in these articles.

http://technet.microsoft.com/en-us/library/cc753609(WS.10).aspx

http://technet.microsoft.com/en-us/library/cc731620(WS.10).aspx

This is good functionality BUT the snapshots are managed by ntdsutil. Not my favourite tool. I can never remember the syntax I need so I decided to wrap the ntdsutil calls in PowerShell functions. I’ve created a module of these functions and they’ll be posted on codeplex in the PowerShell Admin Modules project - http://psam.codeplex.com/

First off we need to create a snapshot

 

001
002
003
004
005
006
007
008
009
010
011
012
013
function new-adsnapshot{
[CmdletBinding()]
param()
PROCESS
{
 
if ( -not ([Security.Principal.WindowsPrincipal]
`
 
[Security.Principal.WindowsIdentity]::GetCurrent()).
IsInRole(`
 
[Security.Principal.WindowsBuiltInRole] "Administrator"
) ){
  
Throw "Must run PowerShell as ADMINISTRATOR to perform these actions"
 }
 
 
ntdsutil "Activate Instance ntds" snapshot create quit quit
}#process
}

 

No parameters to this one – we test if running with elevated privileges and then call ntdsutil to create the snapshot.

These functions have to be run on a domain controller or using powershell remoting to a domain controller.

PAM 0.5–additional info

The reliability and stability metrics are enable by default on Windows 7. On Windows 2008 R2 need to enable them via GPO. Look for Configure Reliability WMI Providers (and enable) in Computer Configuration – Policies – Administrative Templates – Windows Components – Windows Reliability Analysis.

If you don’t do this you will get a Provider Load Failure error.

You may still get the error in which case follow this procedure (thanks to Ed Wilson – Microsoft Scripting Guy)

  • On the server, go to the Task Scheduler
  • Expand the folder to Library > Microsoft > Windows > RAC
  • Right click the RAC Task and go to properties
  • Go to the Triggers tab
  • Go to the 'One time' trigger and click on Edit
  • All the way at the bottom (left), the 'Enabled' checkbox was unchecked.
  • Place a checkmark there
  • Click OK all the way out.
  • Run the task
  • After a couple of minutes should be able to run any of the win32_reliability* classes
    • locally on the server and remotely from a Windows 7 box 

Next job is to see if I can script a check on the task and perform the fix

PAM 0.5

Just released PowerShell Admin Modules (PAM) 0.5.  This adds the PAMStability module for working with stability and reliability metrics on Windows 7 and 2008 R2. The following 2 functions are available:

get-stabilityindex
get-reliabilityrecords

see http://psam.codeplex.com/

Reliability Records

Want to know if there is something affecting the reliability of you system?  For Windows 7 and Windows 2008 R2 WMI providers some reliability metrics. They are enabled by default on Windows 7. group Policy has to be used to enable them on the server side.  See Computer Settings - Administrative Templates – Windows Components - Reliability

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
function get-reliabilityrecords{
[CmdletBinding()]
param (
 [parameter(ValueFromPipeline=$true,
   ValueFromPipelineByPropertyName=$true)]
  [string]$computer=".",
 
  [string]
  [ValidateSet("System", "Application")]
  $logfile,
 
  [string]
  [ValidateSet(
    "Microsoft-Windows-WindowsUpdateClient ",
     "Application Error", 
     "MsiInstaller", 
     "Microsoft-Windows-UserPnp",
     "Application Hang", 
     "Application-Addon-Event-Provider",
     "EventLog")]
     $source
 
)
BEGIN{
 $filt = $null
 if ($logfile) {$filt += "LogFile = '$logfile'"}
 if ($source) {$filt += "AND SourceName ='$source'"}
 if ($filt){ 
   if ($filt.StartsWith("AND ")){$filt = $filt.Remove(0, 4)}
   Write-Debug $filt  
 }
 
}#begin

PROCESS{
 if ($filt){
   Get-WmiObject -Class Win32_ReliabilityRecords -Filter "$filt" -ComputerName $computer |
   select ComputerName, EventIdentifier, InsertionStrings, Logfile, Message,
   ProductName, RecordNumber, SourceName, 
   @{N="TimeGenerated"; E={$_.ConvertToDatetime($_.TimeGenerated)}}, 
   User
 }
 else{
   Get-WmiObject -Class Win32_ReliabilityRecords -ComputerName $computer |
   select ComputerName, EventIdentifier, InsertionStrings, Logfile, Message,
   ProductName, RecordNumber, SourceName, 
   @{N="TimeGenerated"; E={$_.ConvertToDatetime($_.TimeGenerated)}}, 
   User
 } 

}#process
END{}
#end

<# .SYNOPSIS Gets the Reliability Records of the System. This is only valid for Windows 7 and Windows Server 2008 R2 .DESCRIPTION Uses the Win32_ReliabilityRecords class. Records can be filtered by log file and source name .PARAMETER <Parameter-Name> Computer A string containing the computer name to access. .PARAMETER <Parameter-Name> source A string containing the source name used to write to the event logs. .PARAMETER <Parameter-Name> logfile A string containing the event log file name. Accepted values are "System" and "Application" .EXAMPLE get-reliabilityrecords -source "Application Hang" -debug | Format-Table TimeGenerated, ProductName, Message –wrap –AutoSize Returns the records from the Application Hang source .EXAMPLE get-reliabilityrecords -logfile application | Format-Table TimeGenerated, ProductName, Message –wrap –AutoSize Returns the records from the Application event log #>

}

 

The corresponding reliability metrics were covered here http://itknowledgeexchange.techtarget.com/powershell/system-stability/

I’ll be posting the two functions as another PSAM module on codeplex soon

Creating a DHCP server

I needed to add a DHCP server to my Windows 2008 R2 test environment .  I know I can use the ServerManager Module for this so I import the module and use get-command to refresh my memory on the cmdlets

 

PS> Import-Module servermanager
PS> get-command -Module servermanager

CommandType     Name                                      Definition
-----------     ----                                      ----------
Cmdlet          Add-WindowsFeature                        Add-WindowsFeature [-Name] <Feature[]> [-Include...
Cmdlet          Get-WindowsFeature                        Get-WindowsFeature [[-Name] <String[]>] [-LogPat...
Cmdlet          Remove-WindowsFeature                     Remove-WindowsFeature [-Name] <Feature[]> [-LogP...

 

Now we can discover the DHCP related features

PS> Get-WindowsFeature *dhcp*

Display Name                                            Name
------------                                            ----
[ ] DHCP Server                                         DHCP
        [ ] DHCP Server Tools                           RSAT-DHCP

 

I need the server and the tools –  one command does it

PS> Add-WindowsFeature -IncludeAllSubFeature -Name DHCP, RSAT-DHCP

Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True    No             Success   {DHCP Server, DHCP Server Tools}

 

It took longer to write this post than to do the work!

Lenovo W510, Hyper-V and BSOD

Beginning of the week I took delivery of a Lenovo W510 – i7 quad core with Hyper-Threading (Windows sees 8 cores) and 16GB of RAM.  From reviews I’d seen it seemed to run Hyper-V OK so it fitted the bill for a mobile lab.

Partitioned the disk OK and got Windows 2008 R2 installed.  Had to download a few drivers from the Lenovo (IBM) site but everything I needed was there or on the box already.  I’d ordered it with Windows 7 64bit so most of the drivers were available.

Installed Hyper-V and joined it to the domain.

Started moving Virtual Machines on to it and it started crash with a Blue Screen of Death.  Not good & I’m not amused at this point. Eventually got to the point where it wouldn’t start – continual BSOD.  Very not good – my new toy is going back if this continues!

Did some research and it seems there can be a conflict between core parking and Hyper-V.  Core parking is a power saving technology that puts cores to sleep if they are not being used. Hyper-V expects them to be there = BANG.

I booted into the BIOS screen and disabled the power management features on the CPU (and PCI bus for good measure) that enable core parking.  Restarted and everything now seems OK.

I can comfortably run a bunch of VMs and have a reasonable performance. 

Then I discovered that I had to reactivate Windows on all the VMs.  They’d been originally been running on a machine with AMD processor. New processor is Intel.  Its enough of a change to trigger reactivation.

All done and everything seems to work fine.

Time to get Virtual Machine Manager installed and see what that actually does.

PowerShell Tech tips

Two tech tips that I’ve contributed to the Realtime publishers site are now available

Go to http://nexus.realtimepublishers.com/tips.php

and look under Disaster Recovery for

How to Configure a Windows Server 2008 R2 Failover Cluster with Windows PowerShell

 and

How to Configure Data Mirroring in SQL Server 2008 with Windows PowerShell

 

Enjoy

Powershell User Group Live Meeting: Modules


When: Tuesday, Apr 20, 2010 7:30 PM (BST)


Where: Virtual

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

Notes

We will cover the new module functionality introduced with PowerShell v2 with a biref look at some of the functionality available in Windows 7/Windows 2008 R2


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: B3FG29
    Entry Code: Zft%D4B7H
    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.