简体   繁体   English

如何使用 Powershell 启用 SQL 文件流

[英]How to enable SQL Filestream using Powershell

I'm spinning up a SQL server ready for deployment.我正在启动准备部署的 SQL 服务器。 Using AWS userdata, everything is being configured to this stage using PowerShell.使用 AWS 用户数据,使用 PowerShell 将所有内容配置到此阶段。 However, the database needs to have Filestream enabled at level 2, but I can't find a way to do this using PowerShell or any other command-line utility.但是,数据库需要在级别 2 启用 Filestream,但我找不到使用 PowerShell 或任何其他命令行实用程序的方法。

The script I've written for this part is this:我为此部分编写的脚本是这样的:

Import-Module SQLPS -DisableNameChecking
$instanceName = $env:COMPUTERNAME
$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
$server.Configuration.FilestreamAccessLevel.ConfigValue = 2
$server.Alter()
Set-ExecutionPolicy RemoteSigned -force
Invoke-Sqlcmd "EXEC sp_configure filestream_access_level, 2"
Invoke-Sqlcmd "RECONFIGURE"
Get-Service -Name MSSQLSERVER | Restart-Service -force
$server.Properties | clip
$server.Configuration | clip
import-module SQLPS -DisableNameChecking

But it's not enabling Filestream.但它没有启用 Filestream。

Does anyone have any ideas on how I can get this working?有人对我如何使它工作有任何想法吗?

Posting this as an answer in case the blog goes offline.将此作为答案发布,以防博客离线。

This worked for me for SQL Server 2019:这对我来说适用于 SQL Server 2019:

# Enable FILESTREAM
$instance = "MSSQLSERVER"
$wmi = Get-WmiObject -Namespace "ROOT\Microsoft\SqlServer\ComputerManagement15" -Class FilestreamSettings | where {$_.InstanceName -eq $instance}
$wmi.EnableFilestream(3, $instance)
Get-Service -Name $instance | Restart-Service
 
Set-ExecutionPolicy RemoteSigned
Import-Module "sqlps" -DisableNameChecking
Invoke-Sqlcmd "EXEC sp_configure filestream_access_level, 2"
Invoke-Sqlcmd "RECONFIGURE"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM