I create a script to do 2 jobs:
Import CSV file with users email list then assign it to
$emails
Connect to Skype for business online using
-UseOAuth
command within the commandMove-CsUser
with Try and catch switch so if any user didn't move it will save the error toError: $($Error[0])" | Out-File c:\temp\CantFind.txt -Append
and once the script is done I use
notepad.exe c:\temp\CantFind.txt
to open the text file with a list of the users that error out and the reason why they error out.
The script works perfectly the first time I run it. it shows the list of the users in text file call cantfind.txt
. Once I import a new user email list and rerun the script still works perfectly but the text file cantfind.txt
doesn't get updated with the new errors related to the new set of users but it keeps showing the first errors from the first user emails list.
I did try to clear and remove variable commands and I even included a function I founded here on the forums but nothing works cantfind.txt
doesn't store the new errors anymore and even if I deleted the file it will generate a new file with the same errors I got from the first set of users that I run the first time. any suggestions would be welcome.
$emails = Import-Csv -path C:\temp\Userlist1.csv -Header Identity
foreach ($email in $emails)
{
try {
Move-CsUser -Identity $email.Identity -Target sipfed.online.lync.com -Confirm:$false -MoveToTeams -Force -UseOAuth
-BypassAudioConferencingCheck -BypassEnterpriseVoiceCheck -HostedMigrationOverrideUrl
https://adminxx.online.lync.com/HostedMigration/hostedmigrationService.svc
}
catch
{
"Error: $($Error[0])" | Out-File c:\temp\CantFind.txt -Append
}
}
notepad.exe c:\temp\CantFind.txt