Link to home
Start Free TrialLog in
Avatar of patelbg2001
patelbg2001

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of patelbg2001
patelbg2001

ASKER

thanks, I should know better by now :o)
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

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

If future please open new question for additional requests.. :-)
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

User generated imageIt 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..
opened