PowerShell Script for Bulk Updating OneDrive for Business User Site Configurations

Lucas Neves - Texel 5 Reputation points
2024-12-02T15:02:20.6933333+00:00

Is there a PowerShell script to perform a bulk update on the site configuration attributes of each user's OneDrive for Business? I have global administrator roles and want to change the default time zone attributes to UTC -03:00 Brasília in Region and change the Locale to Portuguese (Brazil)

User's image

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,371 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,220 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,999 questions
OneDrive Management
OneDrive Management
OneDrive: A Microsoft file hosting and synchronization service.Management: The act or process of organizing, handling, directing or controlling something.
1,304 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,706 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lucas Neves - Texel 5 Reputation points
    2024-12-16T18:58:19.67+00:00

    @AllenXu-MSFT , thanks for your comment.

    Hello everyone, sorry for the delay in responding. I couldn't do it this way and identified that PnP -Interactive will no longer be available. So I decided to test it another way, using the following scripts:

    # Set Parameters
    $AdminSiteURL="https://TENANT-admin.sharepoint.com"
    $SiteCollAdmin="TENANTADMIN.onmicrosoft.com"
      
    # Connect to PnP Online to the Tenant Admin Site
    Connect-PnPOnline -Url $AdminSiteURL -UseWebLogin
      
    # Get All OneDrive Sites
    $OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
     
    # Loop through each site
    ForEach($Site in $OneDriveSites)
    { 
        # Add Site collection Admin
        Set-PnPTenantSite -Url $Site.URL -Owners $SiteCollAdmin
        Write-Host -f Green "Added Site Collection Admin to: "$Site.URL
    }
    

    Responsible for granting admin access to all OneDrives. And after that, I ran this script:

    # Register EntraIDAPP PNP
    Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP Rocks" -Tenant tenant.onmicrosoft.com -Interactive
    
    # Set Parameters
    $AdminSiteURL = "https://TENANT-admin.sharepoint.com"
    $LanguageID = 1046 # Portuguese (Brazil)
    $TimezoneId = 8 # UTC-03:00 Brasília
    $LocaleId = 1046 # Portuguese (Brazil)
    $ClientId = "CLIENTID"
    
    # Connect to PnP Online using the registered application
    Connect-PnPOnline -Url $AdminSiteURL -Interactive -ClientId $ClientId
    
    # Get All OneDrive for Business Sites
    $OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
    
    # Loop through each site
    ForEach ($Site in $OneDriveSites) {
        Write-Host -ForegroundColor Yellow "Processing Site: $($Site.Url)"
        
        # Connect to OneDrive for Business Site
        Connect-PnPOnline -Url $Site.Url -Interactive -ClientId $ClientId
        
        # Get the Web
        $Web = Get-PnPWeb -Includes RegionalSettings.TimeZones
        
        # Configure the site as multilingual
        $Web.IsMultilingual = $True
        $Web.AddSupportedUILanguage($LanguageID)
        
        # Get the desired time zone
        $Timezone = $Web.RegionalSettings.TimeZones | Where-Object { $_.Id -eq $TimezoneId }
        
        If ($Timezone -ne $Null) {
            # Update the site's time zone
            $Web.RegionalSettings.TimeZone = $Timezone
            Write-Host -ForegroundColor Green "Timezone Updated Successfully!"
        } else {
            Write-Host -ForegroundColor Yellow "Timezone ID $TimezoneId not found!"
        }
        
        # Update the site's locale
        $Web.RegionalSettings.LocaleId = $LocaleId
        
        # Update the Web object
        $Web.Update()
        Invoke-PnPQuery
    }
    

    To set 24-hour time format for each user:

    # Set Parameters
    $AdminSiteURL = "https://TENANT-admin.sharepoint.com"
    $LanguageID = 1046 # Portuguese (Brazil)
    $TimezoneId = 8 # UTC-03:00 Brasília
    $LocaleId = 1046 # Portuguese (Brazil)
    $ClientId = "CLIENTID"
    
    # Connect to PnP Online using the registered application
    Connect-PnPOnline -Url $AdminSiteURL -Interactive -ClientId $ClientId
    
    # Get All OneDrive for Business Sites
    $OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
    
    # Loop through each site
    ForEach ($Site in $OneDriveSites) {
        Write-Host -ForegroundColor Yellow "Processing Site: $($Site.Url)"
        
        # Connect to OneDrive for Business Site
        Connect-PnPOnline -Url $Site.Url -Interactive -ClientId $ClientId
        
        # Get the Web
        $Web = Get-PnPWeb -Includes RegionalSettings.TimeZones
        
        # Configure the site as multilingual
        $Web.IsMultilingual = $True
        $Web.AddSupportedUILanguage($LanguageID)
        
        # Get the desired time zone
        $Timezone = $Web.RegionalSettings.TimeZones | Where-Object { $_.Id -eq $TimezoneId }
        
        If ($Timezone -ne $Null) {
            # Update the site's time zone
            $Web.RegionalSettings.TimeZone = $Timezone
            Write-Host -ForegroundColor Green "Timezone Updated Successfully!"
        } else {
            Write-Host -ForegroundColor Yellow "Timezone ID $TimezoneId not found!"
        }
        
        # Update the site's locale
        $Web.RegionalSettings.LocaleId = $LocaleId
        
        # Set the time format to 24 hours using PowerShell
        $Web.RegionalSettings.Time24 = $True
        
        # Update the Web object
        $Web.Update()
        Invoke-PnPQuery
    }
    

    The OneDrive script was executed using PowerShell ISE and the locale change script was executed using PowerShell 7.4.6.

    1 person found this answer helpful.
    0 comments No comments

  2. AllenXu-MSFT 22,156 Reputation points Microsoft Vendor
    2024-12-03T06:16:06.1133333+00:00

    Hi,

    As an Administrator, you can set the timezone for all OneDrive for Business Sites using PowerShell.

    #Set Parameters
    $AdminSiteURL="https://xxx-admin.sharepoint.com" 
    $TimezoneName = "(UTC-03:00) Brasilia"
    
    #Get Credentials to connect
    $Cred  = Get-Credential
      
    #Connect to PnP Online to the Tenant Admin Site
    Connect-PnPOnline -Url $AdminSiteURL -Credentials $Cred
      
    #Get All OneDrive for Business Sites
    $OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
     
    #Loop through each site
    ForEach($Site in $OneDriveSites)
    {
        Write-Host -f Yellow "Processing Site: "$Site.URL
     
        #Connect to OneDrive for Business Site
        Connect-PnPOnline $Site.URL -Credentials $Cred
      
        #Get the Web
        $web = Get-PnPWeb -Includes RegionalSettings.TimeZones
      
        #Get the time zone
        $Timezone  = $Web.RegionalSettings.TimeZones | Where {$_.Description -eq $TimezoneName}
      
        If($Timezone -ne $Null)
        {
            #Update time zone of the site
            $Web.RegionalSettings.TimeZone = $Timezone
            $Web.Update()
            Invoke-PnPQuery
            Write-host "Timezone Updated Successfully!" -ForegroundColor Green
        }
        else
        {
            Write-host "Timezone $TimezoneName not found!" -ForegroundColor Yellow
        }    } 
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.