Calling a variable with -Filter in Powershell

A.P Hotmail 21 Reputation points
2022-11-21T17:57:38.027+00:00

This works:
Get-CsOnlineUser -Filter {LineURI -eq "tel:+12221234567"} | select UserPrincipalName,LineURI

via import-csv or a foreach loop, I would like to call a variable so that I can check a large group of numbers. This however doesn't work:
import-csv .\NumberCheck.csv | %{Get-CsOnlineUser -Filter {LineURI -eq ($_.LineURI)} | select UserPrincipalName,LineURI}

How do I call a variable when using -Filter?

Windows for business Windows Server User experience PowerShell
Microsoft Teams Microsoft Teams for business Other
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 119.5K Reputation points MVP Volunteer Moderator
    2022-11-21T18:18:32.217+00:00

    Either use a script block or use the quotes syntax:

    Import-CSV .\NumberCheck.csv | % { Get-CsOnlineUser -Filter "LineUri -eq '$($_.LineUri)'" } | select UserPrincipalName,LineURI  
      
    Import-CSV .\NumberCheck.csv | % { Get-CsOnlineUser -Filter ([scriptblock]::Create("LineUri -eq '$($_.LineUri)'")) } | select UserPrincipalName,LineURI  
    
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.