Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Finding and removing values in registry subkeys

Closed Thread
 
Thread Tools Display Modes
Old 03-14-2008   #1 (permalink)
Michael Pope
Guest


 

Finding and removing values in registry subkeys

I have been directed by Microsoft CSS to follow the instructions in KB300956
"How to manually rebuild Performance Counter Library values" on a Windows
SBS 2003 server.

In that KB article, it states to search within
HKLM:\SYSTEM\CurrentControlSet\Services for services that have a Performance
subkey and then to remove the following values from the Performance subkey
if they exist:

- First Counter
- First Help
- Last Counter
- Last Help

I initially attempted to do this manually and found myself still clearing
this from services that started with "D" after an hour's worth of effort.
So, I have been trying to put together a PowerShell script that will do it.

I know that I can Set-Location to HKLM:\SYSTEM\CurrentControlSet\Services
and then I can Get-ChildItem .\*\Performance and see all of the services
that have a Performance subkey. So, I have something to send down the
pipeline.

I just can't figure out how to do the rest. I know that I would use
Remove-ItemProperty to delete the registry values. I have found the
Search-Registry.ps1 script in Lee's book. I just can't figure out how to
make all of the pieces work.

Thank you for any help.


Old 03-14-2008   #2 (permalink)
Marco Shaw [MVP]
Guest


 

Re: Finding and removing values in registry subkeys

Michael Pope wrote:
Quote:

> I have been directed by Microsoft CSS to follow the instructions in KB300956
> "How to manually rebuild Performance Counter Library values" on a Windows
> SBS 2003 server.
>
> In that KB article, it states to search within
> HKLM:\SYSTEM\CurrentControlSet\Services for services that have a Performance
> subkey and then to remove the following values from the Performance subkey
> if they exist:
>
> - First Counter
> - First Help
> - Last Counter
> - Last Help
>
> I initially attempted to do this manually and found myself still clearing
> this from services that started with "D" after an hour's worth of effort.
> So, I have been trying to put together a PowerShell script that will do it.
>
> I know that I can Set-Location to HKLM:\SYSTEM\CurrentControlSet\Services
> and then I can Get-ChildItem .\*\Performance and see all of the services
> that have a Performance subkey. So, I have something to send down the
> pipeline.
Try:
Get-ChildItem .\*\Performance|Foreach-Object{
get-itemproperty -path $_.pspath -name "last counter"
}

So you'd use remove-itemproperty, instead of get-itemproperty. I'm not
checking for the value though, so you may get lots of errors, I'm just
assuming it is there, and if it is, I'm getting it above.

To check for all four:
Get-ChildItem .\*\Performance|Foreach-Object{
get-itemproperty -path $_.pspath -name "last counter"
get-itemproperty -path $_.pspath -name "last help"
get-itemproperty -path $_.pspath -name "first counter"
get-itemproperty -path $_.pspath -name "first help"
}

***Use at your own risk***
***Use at your own risk***
***Use at your own risk***
***Use at your own risk***

Please do a complete backup before running such a widespread delete...

Doing this will remove any error messages if the value is not found:
....
get-itemproperty -path $_.pspath -name "first counter" -erroraction
silentlycontinue
....

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
Old 03-14-2008   #3 (permalink)
Michael Pope
Guest


 

Re: Finding and removing values in registry subkeys

Perfect, Marco. I did a backup of the Services key and then I ran it with a
transcript enabled and the -WhatIf option enabled on all of the
Remove-ItemProperty commands and it did what I thought it would do. So, I
removed that option and ran it for real and it was done in less than five
seconds!

Thank you so much for your help. I am finding more and more real-world uses
for PowerShell.

Michael

"Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:%23lNnpGghIHA.5160@xxxxxx
Quote:

> Michael Pope wrote:
Quote:

>> I have been directed by Microsoft CSS to follow the instructions in
>> KB300956 "How to manually rebuild Performance Counter Library values" on
>> a Windows SBS 2003 server.
>>
>> In that KB article, it states to search within
>> HKLM:\SYSTEM\CurrentControlSet\Services for services that have a
>> Performance subkey and then to remove the following values from the
>> Performance subkey if they exist:
>>
>> - First Counter
>> - First Help
>> - Last Counter
>> - Last Help
>>
>> I initially attempted to do this manually and found myself still clearing
>> this from services that started with "D" after an hour's worth of effort.
>> So, I have been trying to put together a PowerShell script that will do
>> it.
>>
>> I know that I can Set-Location to HKLM:\SYSTEM\CurrentControlSet\Services
>> and then I can Get-ChildItem .\*\Performance and see all of the services
>> that have a Performance subkey. So, I have something to send down the
>> pipeline.
>
> Try:
> Get-ChildItem .\*\Performance|Foreach-Object{
> get-itemproperty -path $_.pspath -name "last counter"
> }
>
> So you'd use remove-itemproperty, instead of get-itemproperty. I'm not
> checking for the value though, so you may get lots of errors, I'm just
> assuming it is there, and if it is, I'm getting it above.
>
> To check for all four:
> Get-ChildItem .\*\Performance|Foreach-Object{
> get-itemproperty -path $_.pspath -name "last counter"
> get-itemproperty -path $_.pspath -name "last help"
> get-itemproperty -path $_.pspath -name "first counter"
> get-itemproperty -path $_.pspath -name "first help"
> }
>
> ***Use at your own risk***
> ***Use at your own risk***
> ***Use at your own risk***
> ***Use at your own risk***
>
> Please do a complete backup before running such a widespread delete...
>
> Doing this will remove any error messages if the value is not found:
> ...
> get-itemproperty -path $_.pspath -name "first counter" -erroraction
> silentlycontinue
> ...
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com

Old 03-15-2008   #4 (permalink)
Marco Shaw [MVP]
Guest


 

Re: Finding and removing values in registry subkeys

Michael Pope wrote:
Quote:

> I have been directed by Microsoft CSS to follow the instructions in KB300956
> "How to manually rebuild Performance Counter Library values" on a Windows
> SBS 2003 server.
I'm surprised they couldn't have provided a script for this...

This is a good example of time-savings provided with PowerShell. I'll
blog about it, and your final solution which is very good/complete for
being able to review all the changes before actually running them.

Marco
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
enumerate registry subkeys knothead VB Script 3 1 Week Ago 12:56 PM
My documents messed up, need help finding registry values!! Respawns Vista file management 3 05-15-2008 02:49 AM
Cannot delete a registry key (or subkeys) --- ??? notaguru Vista General 10 10-29-2007 07:49 PM
need some registry values Michael Vista General 5 03-12-2007 11:01 PM
Info: I need to compare Registry Subkeys between a Model Server and a Server Brandon Shell PowerShell 3 08-27-2006 04:25 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50