Forum Discussion
Zeff Wheelock
Sep 20, 2018Iron Contributor
Results Out Of Order
I have a short function: Write-Host "Missing ATP_ENTERPRISE license" Get-MsolUser -All | sort DisplayName | ? {$_.Licenses.AccountSku.SkuPartNumber -contains "ENTERPRISEPACK"} | ? {$_.Licenses.A...
- Oct 01, 2018
Hi 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!
Matthew Roerig
Oct 01, 2018Copper Contributor
Hi 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!
Zeff Wheelock
Oct 11, 2018Iron Contributor
That seemed to work well! Thanks!