Tìm kiếm trang web

SharePoint Online: Thay đổi múi giờ bằng PowerShell


Yêu cầu: Thay đổi múi giờ trong SharePoint Online.

Làm cách nào để thay đổi múi giờ trong SharePoint Online?

Là một tổ chức toàn cầu hoạt động ở các khu vực và múi giờ khác nhau, chúng tôi muốn đặt múi giờ cho các trang web tương ứng, vì người dùng cảm thấy khó chịu khi họ nhìn thấy múi giờ Thái Bình Dương trong dấu thời gian của tài liệu được tải lên. Trong bài viết này, chúng tôi sẽ hướng dẫn bạn cách thay đổi múi giờ cho SharePoint Online.

Bạn có thể đặt cài đặt múi giờ của SharePoint Online bằng cách đi tới:

  1. Cài đặt trang >> Nhấp vào “Cài đặt khu vực” trong “Quản trị trang”.
  2. Trên trang Cài đặt khu vực, Bạn có thể đặt múi giờ, ngôn ngữ và các cài đặt khu vực khác.

  3. Nhấp vào nút “OK” ở dưới cùng bên phải của trang để lưu các thay đổi của bạn.

Cài đặt múi giờ mới sẽ phản ánh ngay lập tức trong tất cả các dấu thời gian được hiển thị trên danh sách và thư viện cũng như các giá trị trường ngày được sử dụng.

Xin lưu ý, Bạn phải có quyền Quản trị viên tuyển tập trang trên tất cả các tuyển tập trang SharePoint Online để thay đổi cài đặt Khu vực múi giờ. Và bạn cần có Quản trị viên SharePoint Online hoặc Quản trị viên đối tượng thuê để áp dụng nó cho toàn bộ đối tượng thuê.

Nhận danh sách tất cả các múi giờ có sẵn trong SharePoint Online:

Chúng tôi cần ID của múi giờ hoặc mô tả để cập nhật múi giờ của trang SharePoint Online. Để có danh sách các múi giờ, bạn có thể chọn nó từ danh sách Múi giờ thả xuống của trang trên hoặc sử dụng PowerShell này để lấy tất cả danh sách múi giờ có sẵn.


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#SharePoint Online Site URL
$SiteURL = "https://crescent.sharepoint.com/"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $credentials

#sharepoint online powershell to get time zone
$Timezones = $Ctx.Web.RegionalSettings.TimeZones
$Ctx.Load($Timezones)
$Ctx.ExecuteQuery()

#Get Timezone ID and Description
$Timezones | Select ID, Description

Thao tác này sẽ truy xuất tất cả các trường mô tả và ID múi giờ có sẵn.

Bạn cũng có thể tham khảo bài viết này của Microsoft để biết các giá trị múi giờ khả dụng: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ms453853(v=office.15)?redirectedfrom=MSDN

SharePoint Online: Thay đổi múi giờ bằng PowerShell

Sau khi có được ID hoặc mô tả múi giờ, Bạn có thể thay đổi múi giờ bằng tập lệnh PowerShell.


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config parameters for SharePoint Online Site URL and Timezone description
$SiteURL = "https://crescent.sharepoint.com/"
$TimezoneName ="(UTC+04:00) Abu Dhabi, Muscat"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $credentials

#Get all available time zones
$Timezones = $Ctx.Web.RegionalSettings.TimeZones
$Ctx.Load($Timezones)
$Ctx.ExecuteQuery()

#Filter the Time zone to update
$NewTimezone = $Timezones | Where {$_.Description -eq $TimezoneName}

#sharepoint online powershell set time zone
$Ctx.Web.RegionalSettings.TimeZone = $NewTimezone
$Ctx.Web.Update()
$Ctx.ExecuteQuery() 

PnP PowerShell để thay đổi múi giờ trong SharePoint Online:

Dưới đây là cách đặt múi giờ trong SharePoint Online bằng PnP PowerShell.


#Set Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$TimezoneName = "(UTC+04:00) Abu Dhabi, Muscat"

#Connect to SharePoint Online with PnP PowerShell
Connect-PnPOnline -URL $SiteURL -Interactive

#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
}

Tương tự, bạn có thể cập nhật ngôn ngữ, định dạng thời gian và các cài đặt khu vực khác:


$Ctx.web.RegionalSettings.time24 = $True
$Ctx.web.RegionalSettings.LocaleId = 1043

PowerShell này đặt múi giờ mặc định của trang SharePoint Online.

Đặt múi giờ cho tuyển tập trang web SharePoint Online bằng PowerShell:

Vì cài đặt múi giờ được quản lý ở phạm vi trang web (web), nên việc đặt múi giờ trên mỗi trang web rất phức tạp. Thiết đặt múi giờ ở tuyển tập trang cấp cao nhất không tự động ảnh hưởng/truyền bá đến các trang phụ. Vì vậy, hãy thay đổi múi giờ cho tuyển tập trang SharePoint Online bằng PowerShell.


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#function to change Timezone regional settings of a SharePoint Online site
Function Set-SPOTimeZone
{ 
    Param ([Microsoft.SharePoint.Client.Web]$Web,[Microsoft.SharePoint.Client.TimeZone]$Timezone)

    Try
    {
        #Update the timezone of the site
        $Web.RegionalSettings.TimeZone = $NewTimezone
        $Web.Update()
        $Ctx.ExecuteQuery()

        Write-host -f Green "Timezone has been updated for "$Web.Url

        #Get all subsites of the web
        $Ctx.Load($Web.Webs)
        $Ctx.executeQuery()

        #Iterate through each subsites and call the function recursively
        Foreach ($Subweb in $Web.Webs)
        {
            #Call the function to set Timezone for the web
            Set-SPOTimeZone -Web $Subweb -Timezone $NewTimezone
        }
    }
    Catch [System.Exception]
    {
        Write-Hoste -f Red $_.Exception.Message
    }  
}

#Config parameters for SharePoint Online Site Collection URL and Timezone description
$SiteURL = "https://crescent.sharepoint.com/"
$TimezoneName ="(UTC+04:00) Abu Dhabi, Muscat"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $credentials
  
#Get the Root web from given Site Collection URL
$Web = $Ctx.web
$Ctx.Load($Web)

#Get the Time zone to update
$Timezones = $Ctx.Web.RegionalSettings.TimeZones
$Ctx.Load($Timezones)
$Ctx.ExecuteQuery()
$NewTimezone = $Timezones | Where {$_.Description -eq $TimezoneName}
 
#Call the function to set Timezone for the Root web
Set-SPOTimeZone -Web $web -Timezone $NewTimezone

Đặt múi giờ mặc định trong SharePoint Online - Toàn bộ đối tượng thuê

Để đặt múi giờ mặc định cho các trang mới mà bạn sẽ tạo trong tương lai trong SharePoint Online, hãy làm như sau:

  1. Đăng nhập vào Trung tâm quản trị SharePoint >> Nhấp vào “Cài đặt” trong điều hướng bên trái >> Nhấp vào “Tạo trang web”.
  2. Trên trang Tạo Trang, chọn múi giờ mặc định cho tuyển tập trang SharePoint mới.

Điều này đặt múi giờ mặc định cho tuyển tập trang mới mà bạn tạo.

Làm cách nào để thay đổi múi giờ cho tuyển tập trang SharePoint Online hiện có?

Chúng tôi có thể đặt múi giờ cho tất cả các tuyển tập trang hiện có trong SharePoint Online - toàn bộ đối tượng thuê bằng cách sử dụng tập lệnh PowerShell bên dưới. Tập lệnh này chỉ lặp qua tất cả các trang web và thay đổi múi giờ mặc định. Chỉ cần đặt các biến $AdminSiteURL và $TimezoneName trong tập lệnh và cung cấp thông tin xác thực để kết nối với Trung tâm quản trị SharePoint Online một lần.


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#function to change Timezone regional settings of a SharePoint Online site
Function Set-SPOnlineTimeZone([String]$SiteURL,[String]$TimezoneName,[PSCredential]$Cred)
{ 
     Try
     {
        #Setup Credentials to connect
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
        #Set up the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $credentials
  
        #Get the Root web from given URL
        $Web = $Ctx.web
        $Ctx.Load($Web)

        #Get the Time zone to update
        $Timezones = $Web.RegionalSettings.TimeZones
        $Ctx.Load($Timezones)
        $Ctx.ExecuteQuery()
        $NewTimezone = $Timezones | Where {$_.Description -eq $TimezoneName}
 
        #Update the timezone of the site
        $Web.RegionalSettings.TimeZone = $NewTimezone
        $Web.Update()
        $Ctx.ExecuteQuery()

        Write-host -f Green "Timezone has been updated for "$Web.Url

        #Get all subsites of the web
        $Ctx.Load($Web.Webs)
        $Ctx.executeQuery()

        #Iterate through each subsites and call the function recursively
        Foreach ($Subweb in $Web.Webs)
        {
            #Call the function to set Timezone for the web
            Set-SPOnlineTimeZone -SiteURL $Subweb.URL -TimezoneName $TimezoneName -Cred $AdminCredentials
        }
   }
    Catch [System.Exception]
    {
        Write-Host -f Red $_.Exception.Message
    } 
} 

#Config parameters for SharePoint Online Admin Center and Timezone description
$AdminSiteURL = "https://crescent-admin.sharepoint.com/"
$TimezoneName ="(UTC+04:00) Abu Dhabi, Muscat"

#Get credentials to connect to SharePoint Online Admin Center
$AdminCredentials = Get-Credential

#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $AdminCredentials

#Get all Site Collections
$SitesCollection = Get-SPOSite -Limit ALL

#Iterate through each site collection
ForEach($Site in $SitesCollection)
{
    Write-host -f Yellow "Setting Timezone for Site Collection:"$Site.URL

    #Call the function to set Timezone for the site
    Set-SPOnlineTimeZone -SiteURL $Site.URL -TimezoneName $TimezoneName -cred $AdminCredentials
}

Đây là một bài đăng khác về cách đặt múi giờ và các cài đặt vùng khác trong SharePoint Tại chỗ Thay đổi cài đặt vùng, múi giờ, ngôn ngữ trong SharePoint 2013 bằng PowerShell

Bài viết liên quan