foreach.ps1
Function Get-Foo { [cmdletbinding(HelpUri = 'https://mikeoneill.blog/exchange_addin/get-eaicalendareventsofrecurrenceitems/')] Param( [parameter(Mandatory=$false)][array]$UserUPN = 'mike@fieldwestern.onmicrosoft.com', [parameter(Mandatory=$false)]$OutputPath = 'c:\temp', [array]$ExcludedUsers = @('diane@fieldwestern.onmicrosoft.com','meganb@fieldwestern.onmicrosoft.com'), $DaysForwards = 180, $DaysBackwards = 180 #add output date of event and need non-recurrence ) #collection class defined Class Result { [String]$Subject [String]$Attendee [datetime]$DateOfMeeting #[String]$RecurrencePattern #[String]$RecurrenceRange } #loop through multiple users foreach ($UserName in $UserUPN){ $username = $userUPN $startTime = (get-date).AddDays(-$DaysBackwards) $endTime = (get-date).AddDays($DaysForwards) $UserID = (Get-MgUser -userid $UserName).Id #$UserMail = (Get-MgUser -UserId $UserName).Mail [array]$ResultList = @() #region get content #first call needed should be get-mgusercalendarevents $calEvents = Get-MgUserCalendarView -UserId $userId -StartDateTime $startTime -EndDateTime $endTime -All Write-Verbose "`$calEvents is $calEvents" #loop through all returned events foreach ($calEvent in $calEvents) { <# $calEvents.id $calEvent = $calEvents #> <# $calevents.count $calEvent = $calEvents[100] #> Write-Verbose "`$calEvent is $calEvent" $eventID = $calEvent.id Write-Verbose "`$eventID is $eventID" $eventDetails = Get-MgUserEvent -UserId $UserID -EventId $eventId Write-Verbose "`$eventDetails is $eventDetails" [array]$Attendees = $eventDetails.Attendees.EmailAddress | Select-Object -ExpandProperty address #$Attendees | gm #get-member -InputObject $Attendees if ($null -ne $Attendees){ $Compare = Compare-Object -ReferenceObject $Attendees -DifferenceObject $ExcludedUsers if ($Compare.sideindicator -eq '<=') { foreach ($Attendee in $Attendees){ [datetime]$Date = $eventDetails.start.DateTime $Results = New-Object -TypeName Result -Property @{ Attendee = $Attendee Subject = $eventDetails.Subject DateOfMeeting = $Date } $ResultList = $ResultList + $Results } } } } } $ResultList } get-foo Get-service | Where-Object {} { { { { } } } } |