Hi I have been working on a script for a while and I have mot things I won working fine. I am trying to add one last bit I previously have fixed in Excel this is to check if a user is a member of 1 one more listed groups.
The part of my code that is not working is the part that begins with:
Check if user are a member of one or more of the listed groups, if true mark with "Is in group""
I have tried several things to get the correct data to be exported to my csv file but it usually ends up empty where the "exist" value should be.
----
Add-PSSnapin *exchange* # Exchange 2007 is used Function Get-Quota { Param ( [string]$Quota, [string]$DB ) If ($Quota -eq "unlimited") { Return $Database[$DB] } Else { Return $Quota } } #Load ActiveDirectory module Try { Import-Module ActiveDirectory -ErrorAction Stop } Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?"; Exit } $Database = @{} ForEach ($DB in (Get-MailboxDatabase)) { $Database.Add($DB.Name,(New-Object PSObject -Property @{ IssueWarningQuota = $DB.IssueWarningQuota ProhibitSendQuota = $DB.ProhibitSendQuota ProhibitSendReceiveQuota = $DB.ProhibitSendReceiveQuota })) } $Results = @() $Results += ForEach ($User in (Get-ADUser -Filter * -Properties Department,Mail,DistinguishedName,Company,Enabled)) { $Mailbox = Get-Mailbox $User.Name -ErrorAction SilentlyContinue If ($Mailbox) { $Mail = $Mailbox | Get-MailboxStatistics -ErrorAction SilentlyContinue If ($Mail.TotalItemSize.Value -eq $null) { $TotalSize = 0 } Else { $TotalSize = $Mail.TotalItemSize.Value.ToBytes() } New-Object PSObject -Property @{ Name = $User.Name SamAccountName = $User.SamAccountName Email = $User.Mail Department = $User.Department MailboxSize = $TotalSize DistinguishedName = $User.DistinguishedName CompanyName = $User.Company Enabled = $User.Enabled IssueWarningQuota = (Get-Quota $Mailbox.IssueWarningQuota $Mailbox.Database).IssueWarningQuota ProhibitSendQuota = (Get-Quota $Mailbox.ProhibitSendQuota $Mailbox.Database).ProhibitSendQuota ProhibitSendReceiveQuota = (Get-Quota $Mailbox.ProhibitSendReceiveQuota $Mailbox.Database).ProhibitSendReceiveQuota } # Check if user are a member of one or more of the listed groups, if true mark with "Is in group" if ((Get-ADUser $User -Properties memberof).memberof -like "CN=grp1" -or "CN=grp2") { $exist = "IS in group" } Else { $exist = "NOT in group" } } } $Results | Select Name,SamAccountName,Email,Department,MailboxSize,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,CompanyName,DistinguishedName,Enabled,exist | Export-Csv -encoding utf8 c:\Scripts\mydata.csv -NoTypeInformation