Forum Discussion
Anonymous
Feb 20, 2019Get-MsolUser filtered variable
Wonder if anyone can help... > I have a txt file containing a list of user principal names. > I need to return all users if they have a licence and their UPN isn't listed in the TXT file. #Us...
- Feb 20, 2019
Hi,
You can try this script (after replacing your UserName) :
$Results = @();
$Users = Get-Content C:\Users\UserName\UserImport.txt
#Get All Licensed Users & Filtered
$licensedUsers = Get-MsolUser -All | Where-Object { $_.isLicensed -eq $true }
$licensedUsers | ForEach-Object {
If ($Users -notcontains $_.UserPrincipalName)
{
$Results += "$_.UserPrincipalName"
}
}
$Results.LengthOr you can try this script :
$Results = @();
$Users_Txt = Get-Content C:\Users\UserName\UserImport.txt -Raw
#Get All Licensed Users & Filtered
$licensedUsers = Get-MsolUser -All | Where-Object { $_.isLicensed -eq $true }
$licensedUsers | ForEach-Object {
$upn = $_.UserPrincipalName
If ($Users_Txt -notlike "*$upn*")
{
$Results += $upn
}
}
$Results.Length
Kevin_Morgan
Feb 20, 2019Iron Contributor
Hi,
You can try this script (after replacing your UserName) :
$Results = @();
$Users = Get-Content C:\Users\UserName\UserImport.txt
#Get All Licensed Users & Filtered
$licensedUsers = Get-MsolUser -All | Where-Object { $_.isLicensed -eq $true }
$licensedUsers | ForEach-Object {
If ($Users -notcontains $_.UserPrincipalName)
{
$Results += "$_.UserPrincipalName"
}
}
$Results.Length
Or you can try this script :
$Results = @();
$Users_Txt = Get-Content C:\Users\UserName\UserImport.txt -Raw
#Get All Licensed Users & Filtered
$licensedUsers = Get-MsolUser -All | Where-Object { $_.isLicensed -eq $true }
$licensedUsers | ForEach-Object {
$upn = $_.UserPrincipalName
If ($Users_Txt -notlike "*$upn*")
{
$Results += $upn
}
}
$Results.Length