当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何使用 PowerShell 将 SharePoint 内容数据库设置为只读模式?

作者:精品下载站 日期:2024-12-14 14:10:41 浏览:14 分类:玩电脑

如何使用 PowerShell 将 SharePoint 内容数据库设置为只读模式?


要求:使用 PowerShell 将内容数据库设置为 SharePoint Server 中的只读。

解决方案: 在升级、灾难恢复/高可用维护、修补等场景中,我们可能需要将 SharePoint 数据库设置为只读模式。从 SQL Server 将 SharePoint 内容数据库设置为只读模式Management Studio 在另一篇文章中进行了解释:如何使 SharePoint 数据库只读?。这次,我们使用 PowerShell 将内容数据库设置为只读。

提示: 使用 Get-SPContentDatabase |选择名称以获取所有 SharePoint 内容数据库!

PowerShell 将内容数据库设置为只读 SharePoint

先决条件:确保您的服务器/工作站中安装了 SQL Server Management Studio 才能使用以下脚本!


#You may have to adjust the below path according to your SSMS version!
Add-Type -Path "C:\Program Files\Microsoft SQL Server0\SDK\Assemblies\Microsoft.SqlServer.Smo.dll"

#Configuration variables 
$SQLInstance ="Abjsvrv9"
$DatabaseName = "SP16_Content_Crescent_Intranet"

Try {
    #Set the Error Action
    $ErrorActionPreference = "Stop"

    #Get the Server
    $Server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $SQLInstance
      
    #Get the Database
    $Database = $Server.Databases[$DatabaseName]

    $Server.KillAllProcesses($DatabaseName)
    #Set Read only option to True
    $Database.DatabaseOptions.ReadOnly = $true
    $Database.Alter()
    
    Write-host "$($DatabaseName) Database made Read-only" -f Green
}
catch {
 Write-Host "Operation Failed. Find the Error Message below:" -ForegroundColor Red
 Write-Host $_.Exception.Message -ForegroundColor Red
}
finally {
 #Reset the Error Action to Default
 $ErrorActionPreference = "Continue"
}

这使得 SharePoint 中的内容数据库成为只读。要进行验证,您可以导航到 SharePoint 2013 中央管理 >> 应用程序管理 >> 管理内容数据库 >> 检查“数据库只读”标志!

[玩转系统] 如何使用 PowerShell 将 SharePoint 内容数据库设置为只读模式?

如果您导航到上述内容数据库中的任何网站集,您将在 SharePoint 2016 网站中找到维护模式通知!

[玩转系统] 如何使用 PowerShell 将 SharePoint 内容数据库设置为只读模式?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯