【发布时间】:2019-10-13 21:40:45
【问题描述】:
我有以下我们在许多服务器上运行的 powershell 脚本来检索 SQL VersionString:
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" "."
$srv.VersionString
它适用于除一个之外的所有服务器,它返回一个空行。
只跑:
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null
New-Object "Microsoft.SqlServer.Management.Smo.Server" "."
返回:
AuditLevel :
BackupDirectory :
BrowserServiceAccount :
BrowserStartMode :
BuildClrVersionString :
BuildNumber :
ClusterName :
ClusterQuorumState :
ClusterQuorumType :
Collation :
CollationID :
ComparisonStyle :
ComputerNamePhysicalNetBIOS :
DefaultFile :
DefaultLog :
Edition :
ErrorLogPath :
FilestreamLevel :
FilestreamShareName :
HadrManagerStatus :
InstallDataDirectory :
InstallSharedDirectory :
InstanceName :
IsCaseSensitive :
IsClustered :
IsFullTextInstalled :
IsHadrEnabled :
IsSingleUser :
Language :
LoginMode :
MailProfile :
MasterDBLogPath :
MasterDBPath :
MaxPrecision :
NamedPipesEnabled :
NetName :
NumberOfLogFiles :
OSVersion :
PerfMonMode :
PhysicalMemory :
PhysicalMemoryUsageInKB :
Platform :
Processors :
ProcessorUsage :
Product :
ProductLevel :
ResourceLastUpdateDateTime :
ResourceVersionString :
RootDirectory :
ServerType :
ServiceAccount :
ServiceInstanceId :
ServiceName :
ServiceStartMode :
SqlCharSet :
SqlCharSetName :
SqlDomainGroup :
SqlSortOrder :
SqlSortOrderName :
Status :
TapeLoadWaitTime :
TcpEnabled :
VersionMajor :
VersionMinor :
VersionString :
Name : SERVERDR
Version :
EngineEdition :
ResourceVersion :
BuildClrVersion :
DefaultTextMode : True
Configuration : Microsoft.SqlServer.Management.Smo.Configuration
AffinityInfo :
ProxyAccount :
Mail :
Databases :
Endpoints :
Languages :
SystemMessages :
UserDefinedMessages :
Credentials :
CryptographicProviders :
Logins :
Roles :
LinkedServers :
SystemDataTypes :
JobServer :
ResourceGovernor :
ServiceMasterKey :
Settings : Microsoft.SqlServer.Management.Smo.Settings
Information : Microsoft.SqlServer.Management.Smo.Information
UserOptions : Microsoft.SqlServer.Management.Smo.UserOptions
BackupDevices :
FullTextService :
ActiveDirectory :
Triggers :
Audits :
ServerAuditSpecifications :
AvailabilityGroups :
ConnectionContext : Data Source=.;Integrated Security=True;MultipleActiveResultSets=False;Application Name="SQL Management"
Events : Microsoft.SqlServer.Management.Smo.ServerEvents
OleDbProviderSettings :
Urn :
Properties :
UserData :
State : Existing
IsDesignMode : False
DomainName : SMO
DomainInstanceName :
所以问题是,为什么它不返回有关安装在此服务器上的 SQL 的信息?
服务器详情: 视窗 2008 R2 微软 SQL Server 2012 - 11.0.5058.0 (X64) Powershell 5.1版
【问题讨论】:
-
该帐户似乎无权连接到此实例,因此无法检索信息。
-
如何配置它以获得权限?
-
需要注意的是,我是以管理员身份登录的,这是一个完整的管理员,所以我很惊讶它没有查看此信息的权限。
-
Windows 管理员权限不会自动提供 SQL Server 权限。您需要执行 SQL 查询
CREATE LOGIN [YourServer\Administrator] FROM WINDOWS;以便 powershell 脚本可以连接。 -
有没有办法在不创建登录的情况下接收 VersionString?
标签: sql-server powershell sql-server-2012