Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Get-ReceiveConnector output into a hash table Name and PermissionGroups

Hi,
I've been trying to get the connector name and the permissiongroups enabled voa exchange powershell, to generate as part of a hash table which I could use as part of a general audit.  

I was looking for some help with the string data from gathered from $_.permissiongroup parameter as it is a  noteproperty object. I was wondering how I can splt the string correctly so I can use a hash table to compare against

$exsrv = $env:computername
$RC = Get-ReceiveConnector -Server $exsrv | Select-Object name, permis* | Fl * | Out-String

ForEach ($x in $RC) {
$pattern = ":"
$pattern1 = ";"

$x = $x | Out-String
$x = $x.split($Pattern,[System.StringSplitOptions]::RemoveEmptyEntries) | Where-Object {$_ -match '\S'}
$x = $x | ForEach {$_ -replace " ",""}
$x = $x | ForEach {$_ -replace "Name","ConnectorName	"}
$x = $x | ForEach {$_ -replace "PermissionGroups","PermGroups	"}
$x = $x | Out-String
$x = $x.split("",[System.StringSplitOptions]::RemoveEmptyEntries)
$x = $x | ForEach {$_ -replace "ConnectorName",";"}
$x = $x | ForEach {$_ -replace "PermGroups",";"}
$x = $x | ForEach {$_ -replace " ",""}
$x = $x | ForEach {$_ -replace ",",", "}
$x = $x | ForEach {$_ -replace ":",""}
$x = $x | Out-String
$x = $x.substring(1)
$x = $x | ForEach {$_ -replace " ","*"}
$x = $x.split($Pattern1,[System.StringSplitOptions]::RemoveEmptyEntries) | Where-Object {$_ -match '\S'}
#$x = $x | ForEach {$_ -replace ":",""}
#$x = $x.split("",[System.StringSplitOptions]::RemoveEmptyEntries)
$x = $x | Out-String
Write-Host $x -Fore Green
	}

Open in new window

0
patelbg2001
Asked:
patelbg2001
  • 4
  • 3
1 Solution
 
SubsunCommented:
Converting to hash table is simple.. Here is an example..
$Hash = @{}
$exsrv = $env:computername
Get-ReceiveConnector -Server $exsrv | Select-Object name, permis* | %{
$Hash[$_.Name] = $_.PermissionGroups
}
$Hash

Open in new window

0
 
patelbg2001Author Commented:
thanks, I should know better by now :o)
0
 
patelbg2001Author Commented:
How would you qurey each connector in the hashtable?

ForEach ($connector in $Hash['Name']) {
	IF ($connector -ne $check) {
		Write-Host $connector "needs updating" -Fore Red
		} ELSE {
			Write-Host $connector "is cool mamajama" -Fore Green
		}
	}

Open in new window

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
SubsunCommented:
Try.. ForEach ($connector in $Hash.Keys)

If future please open new question for additional requests.. :-)
0
 
patelbg2001Author Commented:
Method invocation failed because [System.Collections.Hashtable] doesn't contain a method named 'keys'

This returns what i need, but how do i check each connector value, matches my variable?

ForEach($item1 in $hash.GetEnumerator()) {Echo $item1.Name}

Open in new window

0
 
SubsunCommented:
Untitled.pngIt does work for me.. If you need more assistance please open a new request, you can explain what you trying to achieve. So we can work on it.. Also it is possible that, there might be a better way to achieve the same..
0
 
patelbg2001Author Commented:
opened
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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