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.
If the logical operator is -like i get :
username is operators or sales people and gets E2
username is operators or sales people and gets E2
username is operators or sales people and gets E2
username is operators or sales people and gets E2
usernames is operators or sales people and gets E2
username is operators or sales people and gets E2
username is operators or sales people and gets E2
username is operators or sales people and gets E2
username is operators or sales people and gets E2
which is not correct because some people are in Corporate OU which are supposed to get an E3 license.
If I change the operator to -match (does not make any sense but just for testing purposes i did it) i get:
Useraname is corporate/callcentermanager or store manager and gets E3
Useraname is corporate/callcentermanager or store manager and gets E3
Useraname is corporate/callcentermanager or store manager and gets E3
Useraname is corporate/callcentermanager or store manager and gets E3
Useraname is corporate/callcentermanager or store manager and gets E3
Useraname is corporate/callcentermanager or store manager and gets E3
Useraname is corporate/callcentermanager or store manager and gets E3
Useraname is corporate/callcentermanager or store manager and gets E3
Useraname is corporate/callcentermanager or store manager and gets E3
which is not right either.
If this makes sense to you I would appreciate your help
Thank you
$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
#$user = Read-Host “name”
$corporate = “OU=Corporate,OU=Users,OU=local,DC=local,DC=local”
$CallCenterManagers = “OU=CallCenter Managers,OU=CallCenter,OU=CFAs,OU=Users,OU=local,DC=local,DC=local”
$Operators = “OU=Operators,OU=CallCenter,OU=CFAs,OU=Users,OU=local,DC=local,DC=local”
$SalesPeople= “OU=Salespeople,OU=Stores,OU=CFAs,OU=Users,OU=local,DC=local,DC=local”
$StoreManagers = “OU=Store Managers,OU=Stores,OU=CFAs,OU=Users,OU=local,DC=local,DC=local”
$path = “C:\New_Users_$currentDate.log”
$When = (Get-Date).Date # today
#$ou = Get-ADUser $user -Properties *| select UserPrincipalName, WhenCreated, Name, distinguishedName # testing purposes
GET ALL USERS CREATED TODAY
$ou = Get-ADUser -SearchBase “ou=Users,ou=glw,dc=globalivewireless,dc=local” -Filter {whenCreated -ge $When1} -Properties * |select UserPrincipalName, Country, name, whencreated, distinguishedname
FOR EVERY NEW USER SET O365 license
foreach($item in $ou){
if(($ou.distinguishedname -match $corporate) -or ($ou.distinguishedname -match $CallCenterManagers) -or ($ou.distinguishedname -match $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 ($ou.distinguishedname -like $SalesPeople)){
else
{
#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}
}
#}