{"id":3308,"date":"2021-06-04T10:08:15","date_gmt":"2021-06-04T09:08:15","guid":{"rendered":"https:\/\/www.dbonline.se\/?p=3308"},"modified":"2021-06-04T14:07:34","modified_gmt":"2021-06-04T13:07:34","slug":"bulk-changing-onedrive-language-of-users","status":"publish","type":"post","link":"https:\/\/www.dbonline.se\/index.php\/2021\/06\/04\/bulk-changing-onedrive-language-of-users\/","title":{"rendered":"Bulk changing OneDrive language of users"},"content":{"rendered":"\n<p>We are a daughter company located in another country than our parent company which means that our shared office 365 tenant has a default language that we don\u2019t daily use.<\/p>\n\n\n\n<p>To not have to change the language settings of every user individually we can use the following script to bulk edit the users based on OU membership.<br><strong>NOTE! This is only for the language settings for example the built in excell in onedrive. This does not change the preferred office365 language.<\/strong><\/p>\n\n\n\n<p>If you have any questions of how it works, contact me.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$UpnPath = \"C:\\OneDriveLanguageScript\\UsersToCheck.txt\"\n$DoneUpnPath = \"C:\\OneDriveLanguageScript\\DoneUsers.txt\"\n$UpnPath = \"C:\\OneDriveLanguageScript\\UsersToCheck.txt\"\n$SiteURL = \"https:\/\/tehoc-admin.sharepoint.com\/\"\n$ODUrl = \"https:\/\/tehoc-my.sharepoint.com\/personal\/\"\n$Locale = \"1053\"\n\n#User Name Password to connect \n$AdminUserName = \"username@domain.com\"\n$AdminPassword = \"apppass\" #App Password\n \n#Prepare the Credentials\n$SecurePassword = ConvertTo-SecureString $AdminPassword -AsPlainText -Force\n$creds = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminUserName, $SecurePassword\n\n$C = Get-ADUser -Filter \"userPrincipalName -like '*'\" -SearchBase 'OU=SWE,DC=domain,DC=com' | Select-Object -Property UserPrincipalName | Out-String\n\n#Creates file with all users UPN\n\nif (!(Test-Path $UpnPath))\n{\n   New-Item -Path \"C:\\OneDriveLanguageScript\\\" -Name \"UsersToCheck.txt\" -ItemType \"file\" -Value $C\n   Write-Host \"Created new file and text content added\"\n}\nelse\n{\n  Remove-Item \u2013path $UpnPath\n  New-Item -Path \"C:\\OneDriveLanguageScript\\\" -Name \"UsersToCheck.txt\" -ItemType \"file\" -Value $C\n  Write-Host \"File already exists so it was cleared and filled with new data\"\n}\n\n(Get-Content $UpnPath | Select-Object -Skip 3) | Set-Content \"C:\\OneDriveLanguageScript\\UsersToCheck.txt\"\nWrite-Host \"Removing first three rows\"\n\n(Get-Content $UpnPath | Foreach {$_.TrimEnd()}) | Set-Content \"C:\\OneDriveLanguageScript\\UsersToCheck.txt\"\nWrite-Host \"removing trailing space of file\"\n\n(Get-Content $UpnPath | ? {$_.trim() -ne \"\" }) | Set-Content \"C:\\OneDriveLanguageScript\\UsersToCheck.txt\"\nWrite-Host \"removing trailing empty lines\"\n\n#Check if there is a file with done users\n\nif (!(Test-Path $DoneUpnPath))\n{\n   New-Item -Path \"C:\\OneDriveLanguageScript\\\" -Name \"DoneUsers.txt\" -ItemType \"file\"\n   Write-Host \"Created new DoneUsers file and text content added\"\n}\n\n#Compare files\n\n$strReference = Get-Content $UpnPath\n$strDifference = Get-Content $DoneUpnPath\n\n#If null array.... ffs....\nif ($strReference -eq $null) { $strReference = \"\" }\nif ($strDifference -eq $null) { $strDifference = \"\" }\n\n#Removes empty inputs\n$strReference = $strReference.Where({ $_ -ne \"\" })\n$strDifference = $strDifference.Where({ $_ -ne \"\" })\n\n#Compares the lists\n$users = Compare-Object $strReference $strDifference\n\nWrite-Host \"Users to change language on\"\nWrite-Host $users.InputObject\n\n#Connect msol service\nConnect-SPOService -Url $SiteURL -Credential $creds\n\n#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM\nAdd-Type -Path \"C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\15\\ISAPI\\Microsoft.SharePoint.Client.dll\"\nAdd-Type -Path \"C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\15\\ISAPI\\Microsoft.SharePoint.Client.Runtime.dll\"\nAdd-Type -Path \"C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\15\\ISAPI\\Microsoft.SharePoint.Client.UserProfiles.dll\"\n\nforeach ($user in $users.InputObject)\n{\n  #Building user ODrive Full Url\n  Write-Host \"Building ODrive Full Url for $user\" -ForegroundColor Yellow\n  $ODriveFullUrl = $ODUrl +  $user.Replace(\"@\",\"_\").replace('.','_')\n  Write-Host $ODriveFullUrl\n  \n  #Adding Admin access to user OneDrive\n  Write-Host \"Adding Admin access to $user OneDrive\" -ForegroundColor Yellow\n  Set-SPOUser -Site $ODriveFullUrl -LoginName $creds.UserName -IsSiteCollectionAdmin $true | Out-Null\n\n  #Bind to OD4B Site and change locale\n  Write-Host \"Changing Locale for $user\" -ForegroundColor Yellow \n  $spocreds = &#91;Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($Creds.UserName,$creds.Password)\n  $Context = New-Object Microsoft.SharePoint.Client.ClientContext($ODriveFullUrl)\n  $return = $Context.Credentials = $spocreds\n  $Context.ExecuteQuery()\n  $Context.Web.RegionalSettings.LocaleId = $Locale                  \n  $Context.Web.Update()\n  $Context.ExecuteQuery()\n  Write-Host $Context\n    \n  #Removing Admin access from User OneDrive\n  Write-Host \"Removing Admin access from $upn OneDrive\" -ForegroundColor Green\n  Set-SPOUser -Site $ODriveFullUrl -LoginName $creds.UserName -IsSiteCollectionAdmin $false | Out-Null\n  Add-Content $DoneUpnPath $user\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We are a daughter company located in another country than our parent company which means that our shared office 365 tenant has a default language that we don\u2019t daily use. To not have to change the language settings of every<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[4,5],"tags":[],"class_list":["post-3308","post","type-post","status-publish","format-standard","hentry","category-it","category-jobb"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8vDvB-Rm","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/posts\/3308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/comments?post=3308"}],"version-history":[{"count":5,"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/posts\/3308\/revisions"}],"predecessor-version":[{"id":3328,"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/posts\/3308\/revisions\/3328"}],"wp:attachment":[{"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/media?parent=3308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/categories?post=3308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbonline.se\/index.php\/wp-json\/wp\/v2\/tags?post=3308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}