Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

List names in registry

1 view
Skip to first unread message

Paul Bergson [MVP-DS]

unread,
Nov 24, 2009, 11:39:06 AM11/24/09
to
I have an applciation that tracks the servers it is connected to within the
registry (Trend Server Protect). I need to extract this data but it isn't
as clean as I would like. I currently have a starting point where I have
set the starting point in HKLM: and execute the following command:

get-childitem -recurse -name | where {$_.attributes -match "*-0"}

Network_phone\SECVIDEO-01-0
Network_phone\WEBCOMMDEV02-0
Odp\ODPDEVCPRD01-0
Odp\ODPDEVETLRD01-0

The output returns both the both the folder (Key) and the sub-folder. This
sub-folder contains the server name along with an appended -0.

I would like the output to contain just the actual computer name.
SECVIDEO01
WEBCOMMDEV02
ODPDEVCPRD01
ODPDEVETLRD01

Are there any commands I can execute to help strip this out simply? I know
how I would do it with vbscript but I need to move on and start using
Powershell.


--
Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4
Microsoft's Thrive IT Pro of the Month - June 2009

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup This
posting is provided "AS IS" with no warranties, and confers no rights.


Chris Dent

unread,
Nov 24, 2009, 12:26:20 PM11/24/09
to

I bumped into a lovely little RegEx not so long ago that would allow you
to grab a value between two characters, excluding the surrounding
characters from the match.

For your example data set, that means something like this:

get-childitem -recurse -name | where {$_.attributes -match "*-0"} | %{
[Void]($_ -Match "(?<=\\).+(?=-)")
If ($Matches) { $Matches[0] } else { $_ }
}

Double \ to escape the RegEx meaning of \. And [Void] to drop the True /
False it would normally return from Match.

Chris

Kryten

unread,
Nov 24, 2009, 12:32:32 PM11/24/09
to
Hi Paul,

I'm sure there will be many other, probably far superior ways, but how
about:-

# Start
$comps = gc comps.txt
[array]$comps2 += $comps | foreach { $([regex]::match($_,"(?<=\\).+(?
=-0)").value) }
$comps2 = $comps2 | foreach { $_ -replace "-" }
$comps2
# End

In that example I'm reading

Network_phone\SECVIDEO-01-0
Network_phone\WEBCOMMDEV02-0
Odp\ODPDEVCPRD01-0
Odp\ODPDEVETLRD01-0

in from a file and sticking them into the $comps array.
The fixed computer names go into $comps2 and I get back:-

SECVIDEO01
WEBCOMMDEV02
ODPDEVCPRD01
ODPDEVETLRD01

Hope it helps,
Stuart

Paul Bergson [MVP-DS]

unread,
Nov 24, 2009, 3:14:04 PM11/24/09
to
I decided to attack it from a different angle and have a started script
below, but the concatenation isn't working as expected. The output I had
hoped for would be a complete path with each folder found instead it is one
long string. Any ideas?

$HKLM = 2147483650
$RemoteComputer = "remoteServer"
$RegObject = Get-WmiObject -List -Namespace root\default -ComputerName
$RemoteComputer | Where-Object {$_.Name -eq "StdRegProv"}
$RegPath =
"Software\trendmicro\serverprotect\currentversion\informationserver\"
$RegKeys = $RegObject.EnumKey($HKLM, $RegPath)

$RegKeys|foreach {
$NewPath = $RegPath + $_.sNames
write-output $NewPath }

--
Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4
Microsoft's Thrive IT Pro of the Month - June 2009

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup This
posting is provided "AS IS" with no warranties, and confers no rights.

"Chris Dent" <ch...@noreply.null> wrote in message
news:%230vP%23sSbK...@TK2MSFTNGP02.phx.gbl...

Paul Bergson [MVP-DS]

unread,
Nov 24, 2009, 3:14:20 PM11/24/09
to
I decided to attack it from a different angle and have a started script
below, but the concatenation isn't working as expected. The output I had
hoped for would be a complete path with each folder found instead it is one
long string. Any ideas?

$HKLM = 2147483650
$RemoteComputer = "remoteServer"
$RegObject = Get-WmiObject -List -Namespace root\default -ComputerName
$RemoteComputer | Where-Object {$_.Name -eq "StdRegProv"}
$RegPath =
"Software\trendmicro\serverprotect\currentversion\informationserver\"
$RegKeys = $RegObject.EnumKey($HKLM, $RegPath)

$RegKeys|foreach {
$NewPath = $RegPath + $_.sNames
write-output $NewPath }

--

Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4
Microsoft's Thrive IT Pro of the Month - June 2009

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup This
posting is provided "AS IS" with no warranties, and confers no rights.

"Kryten" <kryt...@googlemail.com> wrote in message
news:584897ad-ab7e-4237...@1g2000vbm.googlegroups.com...

Kryten

unread,
Nov 24, 2009, 4:48:04 PM11/24/09
to
Hi,

Hard to say without seeing what some of those variables contain.
Might be worth trying explicitly casting $NewPath
as an array.

So the last bit would look more like:-

$RegKeys|foreach {
[array]$NewPath += $RegPath + $_.sNames
write-output $NewPath }

Good luck,
Stuart

0 new messages