Hello Everyone,
I’m trying to find a way to get a full line for each item for this script. I am pulling all of the users from corporate headquarters and getting mobile device information for any device they have connected with in the past 30 days. It works great, but the security folks want to be able to sort the information better. So instead of only having the Identifiable information for the user once, they would like each device to basically be it’s own line.
Here is a screenshot of how the data is currently.
Here is the code that I’m using:
#Define Variables $Data = New-Object System.Collections.ArrayList #$Data = Get-EXOMailbox -ResultSize Unlimited | Sort-Object DisplayName $Data = Import-Csv 'C:\Users\rmartin\Scripts\corp_mobile_upns.csv' $groupamount = 25 $Number = [math]::ceiling($data.count / $groupamount) $Item = New-Object System.Collections.ArrayList $Count = 0 $Inc = 0 $b = 0 #End Variable Definitions #Count up from 0 to ($Data.Count / 100) by 100 users a time to get all employees# For ($count=0; $count -le $Number; $Count++){ $ID = New-Object System.Collections.ArrayList $Users = New-Object System.Collections.ArrayList $Rollup = New-Object System.Collections.ArrayList $i = 0 $Users = $Data | Select-Object -Skip ($Inc+0) -First $groupamount ForEach ($User in $Users) { $ID = Get-EXOMobileDeviceStatistics -UserPrincipalName $User.UserPrincipalName | Where-Object LastSuccessSync -ge (Get-Date).AddDays(-30) | Select-Object DeviceFriendlyName,DeviceID,DeviceModel,DeviceOS,ClientType,ClientVersion,LastSuccessSync if (-NOT ($NULL -eq $ID.DeviceID)) { $Item = [PSCustomObject]@{ 'Name' = $User.DisplayName 'UPN' = $User.UserPrincipalName 'Email' = $User.PrimarySMTPAddress 'Device Friendly Name' = ($ID.DeviceFriendlyName | Out-String).Trim() 'Device ID' = ($ID.DeviceID | Out-String).Trim() 'Device Model' = ($ID.DeviceModel | Out-String).Trim() 'Device OS' = ($ID.DeviceOS | Out-String).Trim() 'Client Type' = ($ID.ClientType | Out-String).Trim() 'Client Version' = ($ID.ClientVersion | Out-String).Trim() 'Last Success Sync' = ($ID.LastSuccessSync | Out-String).Trim() } $Rollup.Add($Item) > $Null } $i++ Write-Progress -activity "Researching Devices" -status "Group: $b of $Number User: $i of $($Users.Count)" -percentComplete (($i / $Users.Count) * 100) } $b++ $Rollup | Export-CSV "C:\Users\rmartin\Documents\Corp Mobile Devices - 9-15-2020.csv" -Append -NoTypeInformation Clear-Variable -Name 'Users' Clear-Variable -Name 'Rollup' $Inc = $Inc+$groupamount }
Thank you everyone for your help and time,
Rob M