Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am totally new to Powershell.

Just started to pick up yesterday. When I found that resource 'Learn Powershell before it is emergence', I realised how apt is the title.

Powershell has already offered a very rich set of primitive to search registry. However, my requirement is a bit more involving.

I want to, given a set of GUID, to locate them all in the registry. Then, in turn, based on the registry keys and values, find out their dependencies.

My goal is to provide a drill-down report of the full COM dependencies.

The basic I need to know are:

1) How to do iteration in powershell?

2) How to keep intemeidate result in an array or list

share|improve this question

3 Answers 3

up vote -1 down vote accepted

1) Use loops. Standard-style For, Foreach and Do/While are all available.

2) Use variables:

$strComputers = @("Server1", "Server2", "Server3")
$strComputers.Count
$strComputers[0]
$strComputers[1]
$strComputers[2]

PowerShell doesn't require strongly typed variables, so watch out for magical conversions. :)

share|improve this answer

Step 1) Get PowerGUI to create your scripts. http://powergui.org/

Step 2) Read the powershell.com chapter on how to access the registry: http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-16-the-registry.aspx

Step 3) Read the powershellpro section on Arrays: http://www.powershellpro.com/powershell-tutorial-introduction/variables-arrays-hashes/

Step 4) Build a script to go through the registry.

What you are asking for is for us to write the script for you. You might try to see what you can build on your own before you ask for help. PowerGUI is a great development environment since you can review your variables once you run the script.

share|improve this answer
    
I DID NOT ask you to write the script for me. I asked two very specific questions on the language construct. –  Anthony Kong Mar 9 '12 at 1:04

Let's try this again.

Iteration in powershell is done in one of three ways:

  1. Use the foreach command on an array: Foreach ($item in $array) { #actions }
  2. Use Powershell select action to build array: $array = Select-childitem -Recurse
  3. Send array down the pipe to a filter: $array | where-object{$_ -like "Search String"}

The easiest way to store intimidate results is to add it to an initialized array variable.

$array = @() #Initialize array
$array += $item #Add item to array

Here is some basic sample code to find something in the registry.

cls
$GUID = "*{3336F667-9049-4D46-98B6-4C743EEBC5B1}*"
$RegPath = "HKLM:\"
$Results = Get-ChildItem $RegPath -Recurse -ErrorAction SilentlyContinue | Where-Object{$_ -like $GUID}
foreach ($item in $Results)
{
    Write-Host $item
}

Using Get-ChildItem is a poor way to search the registry but it does work.

Hope this helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.