Sep 20 2018 10:46 AM - edited Sep 20 2018 10:58 AM
I have a short function:
Write-Host "Missing ATP_ENTERPRISE license"
Get-MsolUser -All | sort DisplayName | ? {$_.Licenses.AccountSku.SkuPartNumber -contains "ENTERPRISEPACK"} | ? {$_.Licenses.AccountSku.SkuPartNumber -notcontains "ATP_ENTERPRISE"}
Write-Host
Write-Host "Missing ENTERPRISEPACK license"
Get-MsolUser -All | sort DisplayName | ? {$_.Licenses.AccountSku.SkuPartNumber -contains "ATP_ENTERPRISE"} | ? {$_.Licenses.AccountSku.SkuPartNumber -notcontains "ENTERPRISEPACK"}
Pause
When I run it, it displays the Write-Host lines ("Missing ATP_ENTERPRISE license", "Missing ENTERPRISEPACK license") then it says Press Any Key To Continue for the pause statement. When I press return, it then displays the missing ATP_ENTERPRISE license results.
I have this script in a function which I call from the same script in a menu system I set up. So, at the end of the script I have a menu and when they choose a number of the menu item it runs the function. The results appear after the Clear-Host command gets run. I assume somehow the results are waiting to be passed back to the main part of the script. If I want the results to be presented within the Function, what do I need to do?:
While ($Main -ne "EXIT")
{
Clear-Host;
Write-Host "Office 365 Reports"
Draw-Box("Mailboxes")
...
Write-Host " 8) Missing ATP_ENTERPRISE License"
""
Write-Host "LOGOFF) Logout and Exit"
Write-Host "EXIT) Exit"
$Main=""
""
$Main=Read-Host "Option"
...
if ($Main -eq "8") {MissingATP}
if ($Main -eq "LOGOFF") {Get-PSSession | Remove-PSSession}
if ($Main -eq "EXIT") {EXIT}
}
Results:
Office 365 Reports
UserPrincipalName DisplayName isLicensed
----------------- ----------- ----------
Joe_Smith@Domain.com Smith, Joe True
Mary_Jones@Domain.com Jones, Mary True
***************
** Mailboxes **
***************
1) Enable Auditing
2) License Report
3) Mailbox Report
4) Inbox Rules and Delegates Report
5) Email Forwarding Report
6) Last Login Report
7) Skype Policies
8) Missing ATP_ENTERPRISE License
LOGOFF) Logout and Exit
EXIT) Exit
Option:
Oct 01 2018 06:07 AM
SolutionHi Zeff,
You can output the results of Get-Msoluser to a variable then use conditionals to display those results. Here is a rough example:
function GetFunc {
$ATP = Get-MsolUser -All | ? {$_.Licenses.AccountSku.SkuPartNumber -contains "ENTERPRISEPACK"} | ? {$_.Licenses.AccountSku.SkuPartNumber -notcontains "ATP_ENTERPRISE"}
$Enterprise = Get-MsolUser -All | ? {$_.Licenses.AccountSku.SkuPartNumber -contains "ATP_ENTERPRISE"} | ? {$_.Licenses.AccountSku.SkuPartNumber -notcontains "ENTERPRISEPACK"}
if($ATP -ne $null){
Write-Host "-> Missing ATP_ENTERPRISE license"
ForEach ($User in $ATP) {Write-Host $User.UserPrincipalName}
Write-Host
}
if($Enterprise -ne $null){
Write-Host "-> Missing ENTERPRISEPACK license"
ForEach ($User in $Enterprise) {Write-Host $User.UserPrincipalName}
Write-Host
}
Pause
}
This is just the first thing that came to mind, there is probably a more elegant solution out there. Let me know if this helps!
Oct 01 2018 06:07 AM
SolutionHi Zeff,
You can output the results of Get-Msoluser to a variable then use conditionals to display those results. Here is a rough example:
function GetFunc {
$ATP = Get-MsolUser -All | ? {$_.Licenses.AccountSku.SkuPartNumber -contains "ENTERPRISEPACK"} | ? {$_.Licenses.AccountSku.SkuPartNumber -notcontains "ATP_ENTERPRISE"}
$Enterprise = Get-MsolUser -All | ? {$_.Licenses.AccountSku.SkuPartNumber -contains "ATP_ENTERPRISE"} | ? {$_.Licenses.AccountSku.SkuPartNumber -notcontains "ENTERPRISEPACK"}
if($ATP -ne $null){
Write-Host "-> Missing ATP_ENTERPRISE license"
ForEach ($User in $ATP) {Write-Host $User.UserPrincipalName}
Write-Host
}
if($Enterprise -ne $null){
Write-Host "-> Missing ENTERPRISEPACK license"
ForEach ($User in $Enterprise) {Write-Host $User.UserPrincipalName}
Write-Host
}
Pause
}
This is just the first thing that came to mind, there is probably a more elegant solution out there. Let me know if this helps!