I've got a variable that I am trying to define in PSCustomObject but it always errors out and will not populate the IsLicesned custom object, the UPN and Department are fine.
$Report += [PSCustomObject]@{
Upn = $ADuser.UserPrincipalName
DEpartment = $ADUser.Department
IsLicensed = $False}
If ($license | where {$_.CapabilityStatus -eq "enabled"}){
**IsLicensed** = $True} <-- trying to define this variable
If I go old school it works:
$CSV = "c:\2022-02-11_UPNreport.csv"
$ImportCSV = import-csv $CSV
$report = @()
foreach ($user in $ImportCSV){
$ADUser = Invoke-Command -scriptblock {Get-AzureADUser -Filter "userprincipalname eq '$($user.UserPrincipalName)'"}
$license = Invoke-Command -scriptblock {Get-AzureADUser -Filter "userprincipalname eq '$($user.UserPrincipalName)'" | select -ExpandProperty AssignedPlans}
$user = New-Object psobject
$user | Add-Member -MemberType NoteProperty -Name UserPrincipalName -Value $null
$user | Add-Member -MemberType NoteProperty -Name Department -Value $null
$user | Add-Member -MemberType NoteProperty -Name IsLicensed -Value $False
$user.userprincipalname = $ADUser.userprincipalname
$user.department = $ADUser.Department
If ($license | where {$_.CapabilityStatus -eq "enabled"}){
$user.IsLicensed = $True}
$report += $user
}
$Report