You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Set-MgUserPhotoContent is returning to the host before it has completed the Graph API to upload the photo file.
I'm using Set-MgUserPhotoContent in a script in a try block where the very next line is a Remove-Item cmdlet to delete a temporary image file. The Remove-Item cmdlet is deleting the file before Set-MgUserPhotoContent has completed the Graph API to upload it which then causes and error for Set-MgUserPhotoContent.
Also tried while using the -PassThru parameter and assigning the output to a variable.
Expected behavior
Set-MgUserPhotoContent should not return until the underlying Graph API call is complete or errored. Or have a parameter that enables it to wait.
DEBUG: [CmdletException]: Received exception with message 'HttpRequestException - An error occurred while sending the
request. : at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RedirectHandler.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RetryHandler.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.CompressionHandler.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Authentication.Handlers.AuthenticationHandler.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Users.d__439.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set.d__69.MoveNext()'
Actually the try block in the script is not working as expected and is executing the next command before going to the catch block. When running the script dot source the try block works correctly. But still don't understand why the Set-MgUserPhotoContent is erroring.
Hi @rleist apologies for the super late response on this issue.
PowerShell cmdlets execute sequentially by default and by wrapping each step in a try-catch block, we ensure the next step only runs if the previous one succeeds.
In a summary here is the implementation of the above.
# Define variables
$user = "joeuser@domain.com"
$file = Get-Item .\tempphoto.jpg
# Update the user's photo
try {
Set-MgUserPhotoContent -UserId $user -InFile $file.FullName -ErrorAction Stop
Write-Host "Photo successfully uploaded for user $user."
} catch {
Write-Error "Failed to upload photo for user $user: $_"
exit 1
}
# Remove the photo file after ensuring the previous task is completed
try {
Remove-Item $file.FullName -Force -ErrorAction Stop
Write-Host "Temporary file successfully deleted: $file.FullName."
} catch {
Write-Error "Failed to delete temporary file: $file.FullName. Error: $_"
}
Kindly also ensure that you upgrade to the latest SDK version (2.25.0) and open a new issue targeting that version
Describe the bug
Set-MgUserPhotoContent is returning to the host before it has completed the Graph API to upload the photo file.
I'm using Set-MgUserPhotoContent in a script in a try block where the very next line is a Remove-Item cmdlet to delete a temporary image file. The Remove-Item cmdlet is deleting the file before Set-MgUserPhotoContent has completed the Graph API to upload it which then causes and error for Set-MgUserPhotoContent.
Also tried while using the -PassThru parameter and assigning the output to a variable.
Expected behavior
Set-MgUserPhotoContent should not return until the underlying Graph API call is complete or errored. Or have a parameter that enables it to wait.
How to reproduce
$user = joeuser@domain.com
$file = get-item .\tempphoto.jpg
Set-MgUserPhotoContent -UserId $user –InFile $file.FullName
Remove-Item $file.FullName -force
SDK Version
2.19.0
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
DEBUG: Content type
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
PUT
Absolute Uri:
https://graph.microsoft.com/v1.0/users/72f917be-3a85-4ee4-9a10-01eeded8c31c/photo/$value
Headers:
FeatureFlag : 00000043
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.14393;
en-US),PowerShell/5.1.14393.6343
Accept-Encoding : gzip
SdkVersion : graph-powershell/2.19.0
client-request-id : fd01ac23-ecae-42c5-8ce4-0164b71f32de
Body:
�����jExif II* � �� �
� ��� � �� ��� � � ��� � � ��� � � ��� � ��� � � ��� � � ��� � � �� � (�� �
� 1�� � �� 2�� � !� ��� � � i�� � 8� %�� � 0� D� NIKON CORPORATION NIKON D7500 ��
�' ��
�' Adobe Photoshop 25.9 (Windows) 2024:06:12
08:27:49 - ��� � Z� ��� � b� "�� � � '�� � d 0�� � � 2�� � d � � 0231��� � j� ��� � ~
� ��� �� ��� �� ��� �� �� � ��� ��� � �� ��
� �� ��� � �� ��
� �� ��� � �� �� � � �� � �� � �
�� � �� �� , �� ��� � 59 ��� � 59 ��� � 59 � � 0100��� � � ��� � �� ��� � �� ��� � ��
��� � � � � � �� � � �� �� ��� � ��� � � ��� � � ��� � H ��� � �� �
�� � �� �
�� � �� �
� ?
2024:06:04 08:10:18 2024:06:04 08:10:18 -04:00 -04:00 -04:00 � � ��F @b� Q @b� � -
h�
ASCII � � ��� � � � � R98 � � 0100 � � � �� � ��� �
� ��� � �� �� � � (�� � � ��� � �� ��� � �� H � H � ���� Adobe_CM ��� �Adobe d� ���
��
���������������������
� ���" �������� �
���? �������� � ����
�� �������� � ����
�� ����������3� ����!�1�AQa�"q�2�����B#$�R�b34r��C%�S���cs5����&D�TdE£t6��U�e���u��F'��������������Vfv��������7GWg
w��������� ������������5� ���!1��AQaq"��2�����B#�R��3$b�r��CS�cs4�%�����&5��D�T��dEU6te����u��F��������������Vfv����
����'7GWgw������� �� ���� ? �k�
�b��
G�J�2r�r^mɺ��:o��{��{��_i,|��?���ϱ��֏�s�RP��*�9;x�s���}]�/�8QK,e��,qv��{�� A$>��E�G�!���ZA�5�d~>�"����� G� a��v���%"В���� ����� �9��v�<�[� ��V�c�@q��>��I ����2�?"(btL��Ħ!������M�2y����☔ܤ��)�T���-�)Md����|W������W������8�{��Z?�O�ǫ�S�� �.��T���;��-�&)m�е��p��N3�z���kckffC�������?K��.������� W�}��� Z���k��;�W��)���CNRk��5��=����
��2JQ�Q%K�
��b�oT���"b;J�pf�����|>�T\���$��D1c���������w �_ӏ/�$�r<��'2�ui�D���n���� ��c� "���������et�ݸ����
�c�
읭��j�
!p�m��S���c5.D�V/�L�Ӿ�]c�[e��������Ԕ�� Y����S�q��}��ݴ���������-���4���\O
��j?N,p�]V#u��h���F�F�@�E���8�#�:�1�1^ͮ� �� h"V�X�����H��pF ����&8p���»ѽ��Iw�z�^;\����^��q��ͬ.��k���Vpe2�&�1�F�_R�;�j~ݻ����G ��#D�O���N���u'���X�W$���W�����;������
'��?���SkI)���@��H�J]��4��������ؒ����{.q� �]@��� ����1\�75��W5��c�x�LI����M��c��s���0����N�o��Lz��-e@n���
��_'?�R��-�����Q"�m.��5��\��Y$Oܣ�@�G�,dOP|�w�!��
]W�Y.���n-s��V���s?�vĢ��O��H�H�n�3��̀9�����v��������@�Y#�kL|���˨�VU;�{mc��������X�|�S]�>�jG�$#BZuVAp�^����� ����w�z��D�
�c@�R�p��>��>��� ����b��r����v��hN֩ �R����S������
����ݭRO��j(Z��H�ȍ��PVc
+�� ���o���=�����1��ȧ�C��1���ձ���?�U��Ҳ�����Ǚ���[�o��'�H�+�����t��M��A�o��������V��1���8w��#?1��X��1��"�ܻ�gn����>b��
��s��8λ�ƪ�����9���kev}�ѻ���d7���_N��$�t��q�9�ջ{�N��W8���^�s����R��c�2}k���o��$��� ̓,��h� �]���ns��-ic���
�����Vs+�~5Y�U���9�c���Ӎ���ҿ�.h��9���1"=������V��{��.��}2u�����$l� F��O��׆�.k}'\K���iy���������v��;h$���52N�˭����):�,�q��qqA���?v
�ӿ���� V����k�S^?G��a��4��'K
�a$� ����J��4W�I�'�sr�Fr�6�X%<"WWtV�"�i��F1Ol��� ��뚤���J3Z�B�hF����B+��/����잃]�������LJP_���R��E��m
o��6ʬie��5�p��=��5�M"�.��d�g�q\�\O&u]oN��X?������������������s����a�k�w�*s�;�
���\�1<|�l�#F� ��ػ]C.���+��x<��������EVL��;��ǩ�z/Z�;��������>{��{�0�r����i
��5{L���^�o�Ozdbj�s$��u������6�K��O�������c��Z�X����_Q�K
K"ڱ�-��:�� m����������釫Y��e�}����}���Ս�7��Hƺ��kb<õ��I>=�f8��j� 5[-^�M��k21�}�����qc��[���E歱��Z�6[�G��<��� ���㨐|��c'���-_l�}_���M�7!���nk����:���vߣ���bװ��
L�}#��n+rniq��ư��X?GN�~w����!�2@Y�$q�M�ѻ��}��� ���>㹿�Q���h���(��S�#�##�D���k$�,d�����B� 6X� r����(.?z �����\p��8 [>�E�s2�Z��j��Q������<.Ȩ�[e �[����� ����y�����n�>!z�^��:�P����kY I%�s���r���ָv���P �d�է 2ӧc�,>�I ������ �K�m۠���,sZ����A�o����6F�$��g��+2���N�� 7�)����6���P�oO��K��X?2�� 8���e_��mlcZ�7k��X���mc��\���Q_P�<��Üy%�3_���-Vp #c�K ��3��?��'kT���������� �79%#y���'(L$������0<��e��I���2������)vĪ�k��t>�oQ�~ګѕ��m���z��� ���~�7T��������=<z����?B�����?w��g�}d������}�,�u�,� �i�SY?D�����S����'ҭ�ĕ[��W�=W��|����u��X��� �iw�ʱ���L�w�����O�~����q�.ø��a� �O����� ��ع���W�OP�!��w{2X�K���s�ݽz�8��X-¹���,����t~��~�\��n�3��FL��e�ߥ�_;��C� �{��z� [�f�����X?�W��@\�Ռ����D>��uo�{7��F� �w����D<T�y�y���P��cP![��2|��X h����cW!���b�F�N��&�-~s�����Z�>�� �W~�� �Q ��ױ������'>��q� �K\� ��O��� "��u��[wSб�R4�fP-g�����g��������3//; ,�M?G��j��$�1���RpO���y/@� �]I�X�t[��lo�b�ɨ��V��/k�� ��� ������ԯ�]G� �Q��������7R��s�H���u}���ͤQ�!��f�5������30r0n5Z��%����;�+��}��T�R�R���j���=F;��%�S2h�-��a�LG��=�� ��e�'��M�9�4:��l��< � ��� >����?�,;��~�
�ٖ�ƭ����=�ߥl����R���5-�䄇�"��R���p���1Cd�Yf�K���_HꙘ�����2o�����[-��������ƍ���C�g����?�
˲�_�+&��~�_�+��m-����F3v���f?�o�����Fڱ
DEBUG: [CmdletException]: Received exception with message 'HttpRequestException - An error occurred while sending the
request. : at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RedirectHandler.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RetryHandler.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.CompressionHandler.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Authentication.Handlers.AuthenticationHandler.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Users.d__439.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set.d__69.MoveNext()'
Configuration
-OS: Windows Server 2016 x64
Name Value
PSVersion 5.1.14393.6343
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.6343
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Other information
No response
The text was updated successfully, but these errors were encountered: