### GLOBAL VARIABLES ###
$end = get-date
$CurrentDate = $end.ToString('MM-dd-yyyy_hh-mm-ss')
$When = (Get-Date).Date # today
$When1 = ((Get-Date).AddDays(-10)).Date #day before
$SKUIDE3 = "company:ENTERPRISEPACK"
$SKUIDE2 = "company:STANDARDPACK"
$path = "C:\New_Users_$currentDate.log"
#$user = Read-Host "name"
$corporate = "OU=Corporate,OU=Users,OU=GLW,DC=local,DC=local"
$CallCenterManagers = "OU=CallCenter Managers,OU=CallCenter,OU=CFAs,OU=Users,OU=GLW,DC=local,DC=local"
$Operators = "OU=Operators,OU=CallCenter,OU=CFAs,OU=Users,OU=GLW,DC=local,DC=local"
$SalesPeople= "OU=Salespeople,OU=Stores,OU=CFAs,OU=Users,OU=GLW,DC=local,DC=local"
$StoreManagers = "OU=Store Managers,OU=Stores,OU=CFAs,OU=Users,OU=GLW,DC=local,DC=local"
$When = (Get-Date).Date # today
#$ou = Get-ADUser $user -Properties *| select UserPrincipalName, WhenCreated, Name, distinguishedName
#$ou.distinguishedName
### GET ALL USERS CREATED TODAY ###
$ou = Get-ADUser -SearchBase "ou=Users,ou=local,dc=local,dc=local" -Filter {whenCreated -ge $When1} -Properties * |select UserPrincipalName, Country, name, whencreated, distinguishedname
$name = $ou.distinguishedname.Split(",",2)
#$name
#switch($ou.distinguishedname)
# {
#{$ou.distinguishedname -like $corporate -or $CallCenterManagers -or $StoreManagers }{Write-Host $item.Name is corporate/callcentermanager or store manager and gets E3 -ForegroundColor yellow}
# {$ou.distinguishedname -like $Operators -or $SalesPeople}{Write-Host $item.Name gets E2 -ForegroundColor green}
# default{Write-Host $item.Name gets E3 -ForegroundColor red}
# }
### FOR EVERY NEW USER SET O365 E3 license ###
foreach($item in $ou){
if($ou.distinguishedname -contains $corporate -or $CallCenterManagers -or $StoreManagers){
#Set-MsolUser -UserPrincipalName $item.UserPrincipalName -UsageLocation $Item.country -Erroraction Stop
#Set-MsolUserLicense -UserPrincipalName $item.UserPrincipalName -AddLicenses $SKUIDE3 -Erroraction Stop
#$WriteLog = "$($item.UserPrincipalName) is licensed with $($SKUIDE3)"
#Add-Content -Path $path -Value $WriteLog
Write-Host $item.Name is corporate/callcentermanager or store manager and gets E3 -ForegroundColor yellow
}
#if($ou.distinguishedname -like $Operators -or $SalesPeople){
else
{
#($ou.distinguishedname -eq $Operators -or $SalesPeople){
#Set-MsolUser -UserPrincipalName $item.UserPrincipalName -UsageLocation $Item.country -Erroraction Stop
#Set-MsolUserLicense -UserPrincipalName $item.UserPrincipalName -AddLicenses $SKUIDE2 -Erroraction Stop
#$WriteLog = "$($item.UserPrincipalName) was licensed with $($SKUIDE2)"
#Add-Content -Path $path -Value $WriteLog
Write-Host $item.Name is operators or sales people and gets E2 -ForegroundColor green}
}
# }
Hi Guys
I am writing this script that will help us auto license new users in O365. The script is not finished yet and I have a logic problem here and I hope you could help me here because I ran out of ideas.
No matter what logic i am using -like, -notlike, -eq, -ne, match or notmatch the results are always the same "$item.Name is corporate/callcentermanager or store manager and gets E3"
For same reason the script does not advance to else statement
I've tried a switch function but i am getting the same results.
Please help.
Thank you