- This topic has 1 reply, 2 voices, and was last updated 2 months, 2 weeks ago by
July 5, 2020 at 6:24 am #240338ParticipantTopics: 1Replies: 0Points: 12Rank: Member
I have a PowerShell script that runs on a schedule to set all of our 150 users profile photos within Office365/Microsoft365.
Here is the code I am using….
$username = “<username>”
$password = “<password>” | ConvertTo-SecureString -asPlainText -Force
$Usercredential = New-Object System.Management.Automation.PSCredential($username,$password)
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Usercredential -Authentication Basic -AllowRedirection
Import-PSSession $ExSession -AllowClobber
Set-UserPhoto -Identity “[email protected]” -PictureData ([System.IO.File]::ReadAllBytes(“C:\photos\user001.jpg”)) -Confirm:$falsecls
Set-UserPhoto -Identity “[email protected]” -PictureData ([System.IO.File]::ReadAllBytes(“C:\photos\user002.jpg”)) -Confirm:$falsecls
Set-UserPhoto -Identity “[email protected]” -PictureData ([System.IO.File]::ReadAllBytes(“C:\photos\user150.jpg”)) -Confirm:$falsecls
The script used to work fine, however recently after about every 10 photos that are changed a prompt appears asking for the password to be re-entered:
Creating a new session for implicit remoting of “Set-UserPhoto” command…
I haven’t changed anything recently so I’m wondering why this is now prompting me?
It’s really annoying as I cannot now run this as a scheduled task.
Can anyone recommend a fix?
July 8, 2020 at 10:13 pm #241211ParticipantTopics: 0Replies: 38Points: 379Rank: Contributor
Try to play with -SessionOption parameter. Create PSsession object using New-PSSessionOption cmdlet and tweak Idletimeout value.
Hope that helps.
- You must be logged in to reply to this topic.