locked
Powershell Newbie - Need help working with a CSV RRS feed

  • Question

  • I've got a command i run to check the MFA device registration status for individual users...

    Get-MsolUser -UserPrincipalName username@company.com |Where-Object {$_.StrongAuthenticationMethods -like"*"} |Select-Object DisplayName,Department -ExpandProperty "StrongAuthenticationMethods"

    Now i need to run this command to check the device registration of multiple users.  I have all users UPN's in a CSV file (Users.csv).

    How do i modify my existing command so that instead of manually changing the individual UPN's ("username@company.com") for each user,  i can instead have it go through the UPN's i've got saved in the CSV?

    Thanks in advance!

    Monday, September 30, 2019 1:39 PM

All replies

  • Hold on. I think i figured it out (it seems to work anyway..)

    +++++

    $A = Import-Csv -Path .\UPNs.csv -Header UserPrincipalName

    $A | Get-MsolUser |Where-Object {$_.StrongAuthenticationMethods -like"*"} |Select-Object DisplayName,Department -ExpandProperty "StrongAuthenticationMethods"

    +++++

    I think it was adding the header that did it.

    Thanks anyway. :)

    Monday, September 30, 2019 2:06 PM
  • If the file contains only UPN's then there's no need to treat it as a CSV.

    Oh . . . and when you post code, use the "Insert Code Block" icon.

    Also, adding a bit of proactive checking on the input data helps prevent unexpected results. :-)

    Get-Content -Path .\UPNs.csv |
        Foreach {
            $upn = $_.trim()
            if ($upn.Length -gt 0) {
                Get-MsolUser -UserPrincipalName $upn | 
                    Where-Object {$_.StrongAuthenticationMethods -like"*"} |
                        Select-Object DisplayName,Department -ExpandProperty StrongAuthenticationMethods 
            }
        }
    
    


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by jrv Monday, September 30, 2019 5:40 PM
    Monday, September 30, 2019 3:43 PM
  • Thanks for the tips Rich. :)
    Monday, September 30, 2019 3:46 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, October 1, 2019 9:20 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Thursday, October 3, 2019 1:43 AM