ForEach($User in $Users)
{
#Get the AD Object based on UPN, which MSonline
$x = Get-ADUser -Filter {UserPrincipalName -eq $User.UserPrincipalName}
#Determine if the account lives in a student OU, otherwise it's staff
If($x.DistinguishedName -ilike $StudentOU)
{
$Students += $x.UserPrincipalName
}
Else
{
if($x) #If there is an object
{
$Faculty += $x.UserPrincipalName
}
else
{
$ProblemAccounts += $User
}
}
}
ForEach($User in $Users)
{
#Get the AD Object based on UPN, which MSonline
$x = Get-ADUser -Filter {UserPrincipalName -eq $User.UserPrincipalName}
#Determine if the account lives in a student OU, otherwise it's staff
If($x.DistinguishedName -ilike $StudentOU)
{
$Students += $x.UserPrincipalName
}
Else
{
if($x) #If there is an object
{
$Faculty += $x.UserPrincipalName
}
else
{
$ProblemAccounts += $User
}
}
}