Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Error querying ADgroup

$
0
0

Hey all,

I am pretty new to powershell and learning as i go. I have created a program that will query my AD to get some usefull information about my AD users.

The things that work so far is getting all the group memberships of the AD user and their email addresses. Now some of the groups the users are member of are groups which also have a email address. I would like to append that data to my output of the group memberships. See the selection of my script below

function UserInformation {
$user = $DropDownBox.SelectedItem.ToString()

try {
$userinfo = get-aduser -identity $user -properties * -ErrorAction STOP

if ($groups.Checked -eq $true) {$Group = "$(($userinfo.memberof -split (",") | Select-string -simplematch "CN=") -replace "CN=",'' | Out-String)"}
if ($email.Checked -eq $true) {if($mail = "$($userinfo.proxyAddresses)" -eq "") {$mail = 'No email found'} else{$mail = $userinfo.proxyAddresses +" `n$($userinfo.msExchArchiveName)"}}

foreach ($g in $group){$(get-adgroup -Identity $g -Properties *).proxyaddress}

$outputBox.text = "$($userinfo.displayName)
Group Memberships:

$group
Email Addresses (SMTP: is primairy): 
$($mail | out-string)
"

     } #end try

catch {$outputBox.text = "`nOperation could not be completed"}

                          }# end UserInformation               

The problem lies in the foreach i try to do. I want to query each group for its proxyaddress. When i try to set the -identity ($g) it will put all results from $group in the -identity. My understanding was that it will put them in one by one thus running the command an x number of times. Obviously i am wrong in my understanding.

After this i still need to format my output and append all the data but first i need to get rid of this error

Can someone help me?



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>