首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >dbatools -安装-DbaInstance- ParameterBinding错误

dbatools -安装-DbaInstance- ParameterBinding错误
EN

Stack Overflow用户
提问于 2022-07-20 18:59:07
回答 2查看 132关注 0票数 0

我试图在dbatools模块中运行,方法是将所需的参数传递给数组中的命令(splatting),但这将返回一个

代码

代码语言:javascript
复制
#set parameters
$Computer = "server01"
$version = 2019
 
#get service account credentials
$sacredential = get-credential -Message "sa account"
$EngineCredential = get-credential -Message "Engine"
$AgentCredential = get-credential -Message "Agent"
 
$config = @{
ComputerName = $Computer
Version = $version
SqlCollation = "Latin1_General_CI_AS"
AuthenticationMode = "Mixed"
Feature = "Engine"
InstancePath = "D:\Program Files\Microsoft SQL Server"
SaCredential = $sacredential
EngineCredential = $EngineCredential
AgentCredential = $AgentCredential
DataPath = "E:\Data"
LogPath = "F:\Log"
TempPath = "G:\TempDB"
BackupPath = "E:\Backup"
PerformVolumeMaintenanceTasks = $true
}

$result = Install-DbaInstance $config
$result | Format-Table
if (-not $result.Successful) {
    throw "Failed to install SQL Server"
}

错误

代码语言:javascript
复制
    Install-DbaInstance : Cannot process argument transformation on parameter 'SqlInstance'. Cannot convert value "System.Collections.Hashtable" to type
    "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]". 
Error: "Cannot convert value "System.Collections.Hashtable" to type "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter". Error: "Failed to interpret input as Instance: System.Collections.Hashtable""

当版本是数组中的第一个参数时,我还收到了一个ParameterBindingValidationException,其有效值为2019年。

代码语言:javascript
复制
Install-DbaInstance : Cannot validate argument on parameter 'Version'. The argument "System.Collections.Hashtable" does not belong to the set "2008,2008R2,2012,2014,2016,2017,2019" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.

如果使用内联的所有参数运行命令,它可以正常工作。我很难理解为什么我要用参数飞溅来获得这些错误,以及如何解决它们。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-07-20 19:18:15

把我的评论移到一个答复上。之所以发生这种情况,是因为当您将参数拆分到cmdlet时,正确的语法是:

代码语言:javascript
复制
Some-Cmdlet @ParamVariable

在您的情况下,您需要使用:

代码语言:javascript
复制
$result = Install-DbaInstance @config
票数 1
EN

Stack Overflow用户

发布于 2022-07-20 19:17:05

正如TheMadTechnician所述,使用散列表作为splat变量时,splatting需要使用@前缀。

关于溅溅

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73056884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档