I am trying to automate my O365 licensing and have had some success, but I am not sure how I can accomplish the following...
I have users who I do not wish to license and they all share the value "svc" in their DisplayName.
In trying to test how this would work I'm dumping the values returned out to a CSV file, but no matter what I do I cannot exclude users with those values in their names. I can do a "contains" and it finds just them...but when I try a "notcontains" I just get all of the users including those with "svc" in their name.
How can I exclude users that have "svc" in their names? Here is my code...
$SyncUser = get-msoluser -all | Where-Object { $_.isLicensed -ne "TRUE" }
Foreach ($a in $SyncUser){
if ($a.DisplayName.NotContains("svc")) {
add-content -value ($a.Userprincipalname) -path $Logfile
}
}