Help with creating powershell array with users from a CSV

Gilbert Mohansen 0 Reputation points
2023-03-05T07:01:12.7033333+00:00

Hi, We are doing a SfB to Teams Phone migration, migrating users in stages.

I've found a script that produces a report for Teams Policies assigned to users but it runs it against the whole tenant, includes filters to create the initial array but I want to run it against a group of users in a CSV. Can anybody tell me how I modify the script so it only runs against users listed in a csv?

Below is a portion of the script, any help is greatly appreciated.


[array]$Users = Get-CsOnlineUser -ResultSize 5000
# Filter the set to get Teams users - this will filter out all but cloud-only Teams users. If you don't want to use the filter, comment it out.
$Users = $Users | Where-Object {$_.InterpretedUserType -eq "PureOnlineTeamsOnlyUser" -or $_.InterpretedUserType -eq "PureOnlineTeamsOnlyUserFailedPublishingToAAD"} | Sort-Object DisplayName
If (!($Users)) {Write-Host "No users found - exiting"; break }
$Report = [System.Collections.Generic.List[Object]]::new()
# Process each user to fetch their policy assignments
ForEach ($User in $Users) {
    $TenantDefaultString = "Tenant Default" 
    $TeamsMeetingPolicy = $TenantDefaultString
    $TeamsMessagingPolicy = $TenantDefaultString
    $TeamsAppSetupPolicy = $TenantDefaultString
    $TeamsAppPermissionsPolicy = $TenantDefaultString
    $TeamsEncryptionPolicy = $TenantDefaultString

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,894 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,967 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kael Yao 37,731 Reputation points Moderator
    2023-03-06T02:33:02.8366667+00:00

    Hi @Gilbert Mohansen

    Please see if the following script would work for you:

    import-csv C:\temp\users.csv | foreach{ Get-CsOnlineUser $_.UPN } | Where-Object {$_.InterpretedUserType -eq "PureOnlineTeamsOnlyUser" -or $_.InterpretedUserType -eq "PureOnlineTeamsOnlyUserFailedPublishingToAAD"} | Sort-Object DisplayName
    If (!($Users)) {Write-Host "No users found - exiting"; break }
    $Report = [System.Collections.Generic.List[Object]]::new()
    # Process each user to fetch their policy assignments
    ForEach ($User in $Users) {
        $TenantDefaultString = "Tenant Default" 
        $TeamsMeetingPolicy = $TenantDefaultString
        $TeamsMessagingPolicy = $TenantDefaultString
        $TeamsAppSetupPolicy = $TenantDefaultString
        $TeamsAppPermissionsPolicy = $TenantDefaultString
        $TeamsEncryptionPolicy = $TenantDefaultString
    
    

    In the csv file you can use the following parameters:

    • GUID
    • SIP address
    • UPN
    • Alias

    just make sure it matches this part:

    foreach{ Get-CsOnlineUser $_.UPN}
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.