• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3469
  • Last Modified:

Registry Subkey Count In Powershell

What is the correct syntax for getting a registry subkey count in Powershell, and if that count passes the If statement, then continue.
I am testing this to see if an Outlook profile has not been setup on this computer than continue, otherwise end script

Here is what I have so far:

Get-ChildItem "hkcu:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
[string]$regKeys = Get-ChildItem "hkcu:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"

If ($regKeys._GetSubKeyCount -lt 5)
      {      
            'Outlook is setup on this computer'
}
Else
      {      
            'Outlook is not setup on this Computer'
}




I don't believe that I have the ._GetSubKeyCount syntax correct. Please advise.
0
MGS-TECH
Asked:
MGS-TECH
2 Solutions
 
jostranderCommented:
Try this sample:
[string]$regKey = "hkcu:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
$(Get-Item $regKey).subkeycount

Open in new window

0
 
illtbaguCommented:
Strange way to do things. It's been a couple of years since I managed exchange server but outlook should do all of this for you. I guess your probably not on exchange. Anyways maybe this might be a better way of doing things
$user = [Environment]::UserName

$foo = Get-ChildItem "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" -recurse -ErrorAction SilentlyContinue `
| ForEach-Object {get-itemproperty -Path $_.PsPath} `
| where {$_."001e6603" -match "$user"}

if ($foo -ne $null) {Write-Host "Outlook profile seems to exist for user $user, abort"} else {Write-Host "No Outlook profile found for $user starting process..."}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now