{"id":86295,"date":"2019-09-04T03:00:16","date_gmt":"2019-09-04T11:00:16","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/scripting\/?p=86295"},"modified":"2019-09-01T14:05:16","modified_gmt":"2019-09-01T22:05:16","slug":"configuring_startup_settings_in_microsoft_teams_with_windows_powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/configuring_startup_settings_in_microsoft_teams_with_windows_powershell\/","title":{"rendered":"Configuring Startup Settings in Microsoft Teams with Windows PowerShell"},"content":{"rendered":"<p><strong>Summary<\/strong>: Using the ConvertFrom-JSON and ConvertTo-JSON Cmdlets to edit a configuration file<\/p>\n<p>Q: Hey, Doctor Scripto!<\/p>\n<p>I need to be able to change the Startup settings in Teams (like the Auto launch feature). I can change it in the Interface, but I need to be able to edit across multiple systems. Could you lend me a hand?<\/p>\n<p>\u2014RL<\/p>\n<p>A: Hello RL,<\/p>\n<p>A very excellent question. For which it produced a most interesting solution when I asked Sean Kearney one of our Microsoft PFE&#8217;s to look at it. Take it away Sean!<\/p>\n<p>Let&#8217;s begin by examining the settings we are trying to change. They can be accessed under the &#8220;Settings&#8221; in Teams<\/p>\n<p><img decoding=\"async\" class=\"wp-image-86296\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image.png\" width=\"300\" height=\"536\" srcset=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image.png 668w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-168x300.png 168w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-573x1024.png 573w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/> <img decoding=\"async\" class=\"wp-image-86297\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-1.png\" width=\"650\" height=\"344\" srcset=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-1.png 1828w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-1-300x159.png 300w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-1-768x407.png 768w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-1-1024x542.png 1024w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>I saw the settings in questions but there didn&#8217;t appear to be a Group Policy which managed them. \u00a0 There was a <a href=\"https:\/\/docs.microsoft.com\/en-us\/deployoffice\/teams-install\">Policy that could be found here to prevent the initial startup that could be found here.<\/a> \u00a0 In addition, if so desired you could edit the XML file for Office Click to run to exclude the installation of Teams if so desired.<\/p>\n<p>But if Teams was deployed and initially an Office wanted to delay use (*after say, until staff were trained*) it would still launch at login in some cases.<\/p>\n<p>Since I couldn&#8217;t find a way online to do it so I decided to investigate. The first question which needed to be answered was &#8220;Where are the settings stored?&#8221;<\/p>\n<p>To find that answer I pulled out the ever trustworthy tool from Sysinternals called <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/procmon\">&#8220;Procmon&#8221;<\/a> which allows you to see what files and registry entries a process is accessing.<\/p>\n<p>If you are curious on how to use this tool there is an excellent link from <a href=\"https:\/\/blogs.msdn.microsoft.com\/chaun\/2014\/06\/06\/basic-steps-for-making-a-process-monitor-procmon-capture\/\">Christopher Haun on MSDN<\/a> as well as a cool <a href=\"https:\/\/www.youtube.com\/watch?v=pjKNx41Ubxw\">video from Scott Hanselman<\/a>. In addition there are books written by Mark Russinovich and Aaron Margosis to show you all the ins and outs of this great suite of tools.<\/p>\n<p>With a little bit of work I found a file which seemed to be written to when I checked and cleared the respective boxes. It was located under the following folder<\/p>\n<p><strong>$ENV:APPDATA\\Microsoft\\Teams\\desktop-config.json<\/strong><\/p>\n<p>Since it was a JSON formatted file, I was able to read it and Convert it to a standard PowerShell object using this piece of PowerShell<\/p>\n<pre title=\"Read TEAMS JSON Configuration with PowerShell\" class=\"lang:ps decode:true\"># Read File into memory and store in $FileContent Object\r\n$FileContent=Get-Content -path \"$ENV:APPDATA\\Microsoft\\Teams\\desktop-config.json\"\r\n# Convert Content from JSON format into a PowerShell Object\r\n$JSONObject=ConvertFrom-Json -InputObject $FileContent<\/pre>\n<p>Once I had this object I could examine the contents (and did of course!)<\/p>\n<p><img decoding=\"async\" width=\"2508\" height=\"1301\" class=\"wp-image-86298\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-2.png\" srcset=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-2.png 2508w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-2-300x156.png 300w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-2-768x398.png 768w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-2-1024x531.png 1024w\" sizes=\"(max-width: 2508px) 100vw, 2508px\" \/><\/p>\n<p>I could see several settings, but one appeared to contain the four I was looking for, &#8220;appPreferenceSettings&#8221;<\/p>\n<p><img decoding=\"async\" class=\"wp-image-86299\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-3.png\" width=\"697\" height=\"148\" srcset=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-3.png 1184w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-3-300x64.png 300w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-3-768x163.png 768w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-3-1024x217.png 1024w\" sizes=\"(max-width: 697px) 100vw, 697px\" \/><\/p>\n<p>I examined one of the values that I was interested in. I needed to know type of an object it contained, in this case the &#8216;openAtLogin&#8217; one. For this we can leverage the <strong>gettype()<\/strong> method which will show us the Type of object it is.<\/p>\n<p><img decoding=\"async\" class=\"wp-image-86300\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-4.png\" width=\"931\" height=\"152\" srcset=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-4.png 1455w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-4-300x49.png 300w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-4-768x126.png 768w, https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/09\/word-image-4-1024x167.png 1024w\" sizes=\"(max-width: 931px) 100vw, 931px\" \/><\/p>\n<p>Knowing this was a Boolean Object, if I wanted to clear the box I needed to set it from $True (checked off) to $False (Cleared)<\/p>\n<p>I updated the value in the following fashion.<\/p>\n<p><strong>$JSONObject.appPreferenceSettings.openAtLogin=$false<\/strong><\/p>\n<p>Now to test this I needed to do three things.<\/p>\n<ol>\n<li>Stop the Teams application<\/li>\n<li>Update the Settings file<\/li>\n<li>Restart the Teams application (and view the settings to see if they had updated)<\/li>\n<\/ol>\n<p># Stop Teams Process<\/p>\n<p>Get-Process Teams | Stop-Process -force<\/p>\n<p>$NewFileContent=$JSONObject | Convertto-JSON<\/p>\n<p># Update Teams Configuration file<\/p>\n<p>$NewFileContent | Set-Content -path &#8220;$ENV:APPDATA\\Microsoft\\Teams\\desktop-config.json&#8221;<\/p>\n<p>I launched the Teams process and examined the settings which confirmed it was updated properly! I actually did a little dance on that one when I saw it work. (No really I did, and Mrs. EnergizedTech looked at me funny when it happened \ud83d\ude09 )<\/p>\n<p>The process then was clearly simple.<\/p>\n<ul>\n<li>Read JSON file configuration<\/li>\n<li>Convert to PowerShell object<\/li>\n<li>Edit Settings in Object<\/li>\n<li>Terminate Teams Process<\/li>\n<li>Update Settings<\/li>\n<\/ul>\n<p>Here it was written as a Parameterized Script<\/p>\n<pre title=\"Editing the TEAMS Configuration with PowerShell\" class=\"lang:ps decode:true\">param(\r\n# Teams open in the background Hidden $true or $false\r\n[boolean]$OpenAsHidden=$False,\r\n# Teams open automatically at user login $true or $false\r\n[boolean]$OpenAtLogin=$False,\r\n# Close Teams App fully instead of running on Taskbar $true or $false\r\n[boolean]$RunningOnClose=$False\r\n)\r\n# Get Teams Configuration\r\n$FileContent=Get-Content -Path \"$ENV:APPDATA\\Microsoft\\Teams\\desktop-config.json\"\r\n# Convert file content from JSON format to PowerShell object\r\n$JSONObject=ConvertFrom-Json -InputObject $FileContent\r\n# Update Object settings\r\n$JSONObject.appPreferenceSettings.OpenAsHidden=$OpenAsHidden\r\n$JSONObject.appPreferenceSettings.OpenAtLogin=$OpenAtLogin\r\n$JSONObject.appPreferenceSettings.$RunningOnClose=$RunningOnClose\r\n# Terminate Teams Process\r\nGet-Process Teams | Stop-Process -Force\r\n# Convert Object back to JSON format\r\n$NewFileContent=$JSONObject | ConvertTo-Json\r\n# Update configuration in file\r\n$NewFileContent | Set-Content -Path \"$ENV:APPDATA\\Microsoft\\Teams\\desktop-config.json\"<\/pre>\n<p>&nbsp;<\/p>\n<p>Now with this script it was possible to update the settings in an easier fashion whether by Group Policy, Login script or any one of many other options.<\/p>\n<p>I hope you found this of use in one of three ways<\/p>\n<ol>\n<li>This solved a problem for you in updating settings<\/li>\n<li>Learning how to edit JSON files with PowerShell<\/li>\n<li>Discovering the cool tools like ProcMon <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/procmon\">Sysinternals<\/a> offers<\/li>\n<\/ol>\n<p>Thanks Sean for sharing that with us! So RL that is all there is to editing the Teams configuration with PowerShell.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Your good friend, Doctor Scripto<\/strong><\/p>\n<p>PowerShell, Doctor Scripto, Sean Kearney, JSON, Teams, Sysinternals, Procmon<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Using the ConvertFrom-JSON and ConvertTo-JSON Cmdlets to edit a configuration file Q: Hey, Doctor Scripto! I need to be able to change the Startup settings in Teams (like the Auto launch feature). I can change it in the Interface, but I need to be able to edit across multiple systems. Could you lend me [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1739,1965,1966,1738,683],"tags":[1740,621,377,1969,154,1968,1967],"class_list":["post-86295","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-doctor-scripto","category-json","category-microsoft-teams","category-powershell","category-text-files","tag-doctor-scripto","tag-json","tag-powershell","tag-procmon","tag-sean-kearney","tag-sysinternals","tag-teams"],"acf":[],"blog_post_summary":"<p>Summary: Using the ConvertFrom-JSON and ConvertTo-JSON Cmdlets to edit a configuration file Q: Hey, Doctor Scripto! I need to be able to change the Startup settings in Teams (like the Auto launch feature). I can change it in the Interface, but I need to be able to edit across multiple systems. Could you lend me [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=86295"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/86295\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=86295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=86295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=86295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}