none
Set-userphoto doesn't work RRS feed

  • Question

  • Hello,

    I need to create a script who add a photo for each user in Powershell but script doesn't work.

    $UserCredential = Get-Credential 
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
    Import-PSSession $Session -AllowClobber
    
    $photo = Get-ChildItem "path\*"
    foreach ($photo1 in $photo){
    $name = $photo1.name
    $namesext = $name -replace('.jpg','')
    $namesext
    Set-UserPhoto -Identity "prenom.nom" -PictureData ([System.IO.File]::ReadAllBytes("O:\Photo Trombi\Modifiées\a_importer_dans_office\$namesext.png"))
    }
    
    
    Remove-PSSession $Session

    And I have that like error message :

    "AVERTISSEMENT : Les noms de certaines commandes importées du module « tmp_jzrdfb
    nd.jqg » contiennent des verbes non approuvés qui peuvent les rendre moins détec
    tables. Pour trouver les commandes comportant des verbes non approuvés, réexécut
    ez la commande Import-Module avec le paramètre Verbose. Pour obtenir la liste de
    s verbes approuvés, tapez Get-Verb.

    ModuleType Version Name ExportedCommands
    ---------- ------- ---- ----------------
    Script 1.0 tmp_jzrdfbnd.jqg {Add-AvailabilityA...
    Erreur sur la commande proxy «Set-UserPhoto -Identity:'first.name' -PictureDat
    a:'255','216','255','225','31','254','69','120','105','102','0','0','73','73','
    42','0','8','0','0','0','10','0','14','1','2','0','32','0','0','0','134','0','0
    ','0','15','1','2','0','6','0','0','0','166','0','0','0','16','1','2','0','25',
    '0','0','0','172','0','0','0','18','1','3','0','1','0','0','0','1','0','0','0', ("its very long text")

    Some can help me?



    • Edited by trunksdu75 Thursday, April 19, 2018 12:04 PM
    Wednesday, April 18, 2018 1:04 PM

Answers

  • I find a solution. It was my url for connect at exchange who was wrong.

    I need to use

     New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxymethod=rps -Credential $UserCredential -Authentication Basic -AllowRedirection

    • Marked as answer by trunksdu75 Thursday, April 19, 2018 2:50 PM
    Thursday, April 19, 2018 2:50 PM

All replies

  • Please post the error message in English.

    To avoid this warning message (not error message), add -DisableNameChecking to your New-PSSession command.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 18, 2018 2:15 PM
    Moderator
  • the error is :

    ModuleType Version    Name                                ExportedCommands     
    ---------- -------    ----                                ----------------     
    Script     1.0        tmp_cbvxbcj0.sen                    {Add-AvailabilityA...
    XXXX
    What if: the picture for the user "user" will be modified.
    Error on the cmdlet proxy «Set-UserPhoto -Identity:'user' -PictureD
    ata:'255','216','255','225','0','24','69','120','105','102','0','0','73','73','
    42','0','8','0','0','0','0','0','0','0','0','0','0','0','255','236','0','17','6
    8','117','99','107','121','0','1','0','4','0','0','0','60','0','0','255','225',
    '3','119','104','116','116','112','58','47','47','110','115','46','97','100','1
    11','98','101','46','99','111','109','47','120','97','112','47','49','46','48',
    '47','0','60','63','120','112','97','99','107','101','116','32','98','101','103
    ','105','110','61','34','239','187','191','34','32','105','100','61','34','87',
    '53','77','48','77','112','67','101','104','105','72','122','114','101','83','1
    22','78','84','99','122','107','99','57','100','34','63','62','32','60','120','
    58','120','109','112','109','101','116','97','32','120','109','108','110','115'
    ,'58','120','61','34','97','100','111','98','101','58','110','115','58','109','
    101','116','97','47','34','32','120','58','120','109','112','116','107','61','3
    4','65','100','111','98','101','32','88','77','80','32','67','111','114','101',
    '32','53','46','54','45','99','49','51','56','32','55','57','46','49','53','57'
    ,'56','50','52','44','32','50','48','49','54','47','48','57','47','49','52','45
    ','48','49','58','48','57','58','48','49','32','32','32','32','32','32','32','3
    2','34','62','32','60','114','100','102','58','82','68','70','32','120','109','
    108','110','115','58','114','100','102','61','34','104','116','116','112','58',
    '47','47','119','119','119','46','119','51','46','111','114','103','47','49','5
    7','57','57','47','48','50','47','50','50','45','114','100','102','45','115','1
    21','110','116','97','120','45','110','115','35','34','62','32','60','114','100
    ','0','35','255','217' -WhatIf:$True -Verbose:$True -Confirm:$False» into the
    server XXXXXX.domaine.com: version of server
    15.20.0675.0000, methodproxy PSWS :
    the task has return an error with the message:
    The underlying connection was closed: An unexpected error occurred on a
    receive...
        + CategoryInfo          : NotSpecified: (:) [Set-UserPhoto], CmdletProxyEx
       ception
        + FullyQualifiedErrorId : Microsoft.Exchange.Configuration.CmdletProxyExce
       ption,Microsoft.Exchange.Management.RecipientTasks.SetUserPhoto
        + PSComputerName        : outlook.office365.com

    With other test I can see :

    -The command is ok with my profil (i've got admin profil)

    -The commande is not ok with an non admin profil...


    Thursday, April 19, 2018 12:58 PM
  • I find a solution. It was my url for connect at exchange who was wrong.

    I need to use

     New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxymethod=rps -Credential $UserCredential -Authentication Basic -AllowRedirection

    • Marked as answer by trunksdu75 Thursday, April 19, 2018 2:50 PM
    Thursday, April 19, 2018 2:50 PM