When I upgraded to TFS 2017 Update 2 this last weekend, my CI build processes started to fail with an error trying to check in code. It was working last week, not this week. I have looked at the Powershell script and I think they broke how they make the environment variable BUILD_QUEUEDBY and so causes issues. I am not sure what would be a good fix for your script until Microsoft fixes and releases a fix to their problem. I guess I could take the script you have, modify it to work and disable the step using your script until they fix their issue.
The error I receive is:
System.Management.Automation.MethodInvocationException: Exception calling "CheckIn" with "1" argument(s): "TF14045: The identity Microsoft.TeamFoundation.System is not a recognized identity." ---> Microsoft.TeamFoundation.VersionControl.Client.IdentityNotFoundException: TF14045: The identity Microsoft.TeamFoundation.System is not a recognized identity. ---> System.Web.Services.Protocols.SoapException: TF14045: The identity Microsoft.TeamFoundation.System is not a recognized identity.
When I upgraded to TFS 2017 Update 2 this last weekend, my CI build processes started to fail with an error trying to check in code. It was working last week, not this week. I have looked at the Powershell script and I think they broke how they make the environment variable BUILD_QUEUEDBY and so causes issues. I am not sure what would be a good fix for your script until Microsoft fixes and releases a fix to their problem. I guess I could take the script you have, modify it to work and disable the step using your script until they fix their issue.
The error I receive is: System.Management.Automation.MethodInvocationException: Exception calling "CheckIn" with "1" argument(s): "TF14045: The identity Microsoft.TeamFoundation.System is not a recognized identity." ---> Microsoft.TeamFoundation.VersionControl.Client.IdentityNotFoundException: TF14045: The identity Microsoft.TeamFoundation.System is not a recognized identity. ---> System.Web.Services.Protocols.SoapException: TF14045: The identity Microsoft.TeamFoundation.System is not a recognized identity.
I added to the following item at Microsoft's Developer Community pages: https://developercommunity.visualstudio.com/content/problem/98797/scheduled-builds-get-microsoftteamfoundationsystem.html
I think if something can be done in the code for now it would become usable again