Exchange Online - Get-UserPhoto - how to catch non terminating error?

前端 未结 2 1649
逝去的感伤
逝去的感伤 2020-12-20 02:40

I\'m trying to export a list of all users with no photo from our Exchange Online account using powershell. I cannot get it to work and have tried various methods.

G

2条回答
  •  难免孤独
    2020-12-20 03:22

    You can throw your own error like so:

    try {
        $error.Clear()
        $user | Get-UserPhoto 
        if ($error[0].CategoryInfo.Reason -eq "UserPhotoNotFoundException") {throw "UserPhotoNotFoundException" }
    } catch {
        #code
    }
    

提交回复
热议问题