Get-CsOnlineUser - Cannot filter with boolean attributes due to casting errors

%3CLINGO-SUB%20id%3D%22lingo-sub-2597030%22%20slang%3D%22en-US%22%3EGet-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597030%22%20slang%3D%22en-US%22%3E%3CP%3ESince%20Friday%20July%2020th%202021%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEvery%20time%20I%20run%20a%26nbsp%3B%3CSTRONG%3EGet-CsOnlineUser%26nbsp%3B%3C%2FSTRONG%3Ewith%20a%20Filter%20on%20a%20boolean%20attribute%2C%20I%20am%20getting%20an%20error.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EExample%201%3A%3C%2FSTRONG%3E%20Getting%20users%20with%20Voice%20Enabled%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EGet-CsOnlineUser%20-Filter%20%7BEnterpriseVoiceEnabled%20-eq%20%24true%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EExample%202%3A%26nbsp%3B%3C%2FSTRONG%3EGetting%20Enabled%20Users%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EGet-CsOnlineUser%20-Filter%20%7BEnabled%20-eq%20%24true%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%26nbsp%3B%3CSTRONG%3EResponse%3C%2FSTRONG%3E%20I%20get%20is%20always%3CSTRONG%3E%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EGet-CsOnlineUser%3A%20Cannot%20bind%20parameter%20'Filter'%20to%20the%20target.%20Exception%20setting%20%22Filter%22%3A%20%22Unable%20to%20cast%20object%20of%20type%20'System.Boolean'%20to%20type%20'System.String'.%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20what%20could%20be%20happening%20here%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2597030%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowershell%20Microsoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2597806%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597806%22%20slang%3D%22en-US%22%3ESame%20thing%20here!!!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2597462%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597462%22%20slang%3D%22en-US%22%3EExactly!!%20I%20was%20really%20going%20crazy%2C%20checking%20if%20anything%20changed%20on%20our%20end%20with%20our%20scripts%2C%20the%20version%20of%20powershell%20or%20the%20cmdlet.%20I%20have%20opened%20a%20ticket%20with%20them%20and%20waiting%20for%20a%20response.%20I%20will%20update%20this%20thread%20the%20moment%20I%20have%20an%20update.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2597457%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597457%22%20slang%3D%22en-US%22%3E%3CP%3EI%20started%20getting%20this%20error%20a%20couple%20days%20ago%20as%20well.%20It%20was%20working%20Thursday%20or%20Friday%2C%20but%20is%20now%20producing%20this%20error.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2597293%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597293%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1111715%22%20target%3D%22_blank%22%3E%40ckarawani-dev%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20tried%20and%20I%20seem%20to%20have%20the%20same%20problem.%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20the%20Microsoft%20Teams%20Version%202.3.1%20module%20installed.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2601458%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2601458%22%20slang%3D%22en-US%22%3EI%20am%20having%20the%20same%20issue.%20have%20you%20received%20any%20updates%20yet%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2601768%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2601768%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20ticket%20is%20still%20open.%20Their%20support%20resource%20provided%20a%20wrongful%20suggestion%20using%3CSTRONG%3E%20%22%24true%22%3C%2FSTRONG%3E%20as%20true%20and%20%3CSTRONG%3E%22%24null%22%3C%2FSTRONG%3E%20as%20false.%20This%20is%20not%20a%20valid%20solution%20as%20any%20non-empty%20string%20would%20resolve%20true.%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20now%20%2C%20the%20two%20viable%20workarounds%20I%20identified%20are%3A%3CBR%20%2F%3E%3CBR%20%2F%3E1.%20Using%20any%26nbsp%3B%3CSTRONG%3Enon-empty%20string%20(ex.%20'banana')%20as%20true%3C%2FSTRONG%3E%20and%20an%20%3CSTRONG%3Eempty%20string%20''%20as%20false.%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CEM%3ENot%20ideal%20and%20a%20bit%20of%20a%20hack%20using%20an%20empty%2Fnon-empty%20string%20as%20my%20flags.%3C%2FEM%3E%3CBR%20%2F%3E%3CBR%20%2F%3E2.%20Using%3CSTRONG%3E%20Where-Object%3C%2FSTRONG%3E%20%7B%24_.EnterpriseVoiceEnabled%20-eq%20%24true%7D%20instead.%3CBR%20%2F%3E%3CEM%3EAlso%20not%20ideal%20as%20it%20is%20way%20less%20efficient%20as%20it%20first%20fetches%20the%20non-filtered%20results%20to%20then%20discard%20a%20bunch%20via%20the%20Where-Object.%3C%2FEM%3E%3CBR%20%2F%3E%3CBR%20%2F%3EStill%20waiting%20on%20a%20better%20fix.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2601933%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2601933%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1111715%22%20target%3D%22_blank%22%3E%40ckarawani-dev%3C%2FA%3E%26nbsp%3Bthank%20you%20for%20the%20update.%20making%20those%20changes%20on%20my%20scripts%20worked.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2634281%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2634281%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1111715%22%20target%3D%22_blank%22%3E%40ckarawani-dev%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20had%20the%20issue%20for%20just%20over%20a%20week%2C%20I%20have%20run%20my%20original%20scripts%20without%20the%20workaround%20below%20and%20the%20issue%20appears%20to%20be%20resolved%20I%20do%20NOT%20receive%20the%20error%20now%20using%20filters%20as%20below%3C%2FP%3E%3CP%3Eget-csonlineuser%20-filter%20%7B(Enterprisevoiceenabled%20-eq%20%24true)%20-and%20(enabled%20-eq%20%24true)%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2634416%22%20slang%3D%22en-US%22%3ERe%3A%20Get-CsOnlineUser%20-%20Cannot%20filter%20with%20boolean%20attributes%20due%20to%20casting%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2634416%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1125434%22%20target%3D%22_blank%22%3E%40jeffkelly%3C%2FA%3E%26nbsp%3B%20wow!%20You're%20right!%20It%20is%20indeed%20fixed.%20I'm%20really%20not%20sure%20what%20we're%20supposed%20to%20do%20in%20the%20future%20when%20these%20types%20of%20issues%20occur.%20Opening%20a%20service%20request%20via%20the%26nbsp%3BMicrosoft%20365%20admin%20center%20(admin.microsoft.com)%20didn't%20really%20help%20much%20as%20they%20were%20not%20really%20aware%20of%20the%20problem%20and%20could%20not%20provide%20any%20explanation%20or%20support%20around%20the%20Microsoft%20Teams%20cmdlet.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Since Friday July 20th 2021, 

 

Every time I run a Get-CsOnlineUser with a Filter on a boolean attribute, I am getting an error. 

 

Example 1: Getting users with Voice Enabled:

 

 

Get-CsOnlineUser -Filter {EnterpriseVoiceEnabled -eq $true}

 

 

 

Example 2: Getting Enabled Users:

 

 

Get-CsOnlineUser -Filter {Enabled -eq $true}

 

 

 

The Response I get is always:

 

 

Get-CsOnlineUser: Cannot bind parameter 'Filter' to the target. Exception setting "Filter": "Unable to cast object of type 'System.Boolean' to type 'System.String'."

 

 

 

Any ideas what could be happening here?

9 Replies

@ckarawani-dev 

 

Just tried and I seem to have the same problem. 

I have the Microsoft Teams Version 2.3.1 module installed. 

 

I started getting this error a couple days ago as well. It was working Thursday or Friday, but is now producing this error.

Exactly!! I was really going crazy, checking if anything changed on our end with our scripts, the version of powershell or the cmdlet. I have opened a ticket with them and waiting for a response. I will update this thread the moment I have an update.
I am having the same issue. have you received any updates yet?

The ticket is still open. Their support resource provided a wrongful suggestion using "$true" as true and "$null" as false. This is not a valid solution as any non-empty string would resolve true.

For now , the two viable workarounds I identified are:

1. Using any non-empty string (ex. 'banana') as true and an empty string '' as false.
Not ideal and a bit of a hack using an empty/non-empty string as my flags.

2. Using Where-Object {$_.EnterpriseVoiceEnabled -eq $true} instead.
Also not ideal as it is way less efficient as it first fetches the non-filtered results to then discard a bunch via the Where-Object.

Still waiting on a better fix.

@ckarawani-dev thank you for the update. making those changes on my scripts worked. 

@ckarawani-dev 

I had the issue for just over a week, I have run my original scripts without the workaround below and the issue appears to be resolved I do NOT receive the error now using filters as below

get-csonlineuser -filter {(Enterprisevoiceenabled -eq $true) -and (enabled -eq $true)}

@jeffkelly  wow! You're right! It is indeed fixed. I'm really not sure what we're supposed to do in the future when these types of issues occur. Opening a service request via the Microsoft 365 admin center (admin.microsoft.com) didn't really help much as they were not really aware of the problem and could not provide any explanation or support around the Microsoft Teams cmdlet.