【发布时间】:2018-06-06 15:28:27
【问题描述】:
我是发帖新手,也是 powershell DSC 和 powershell 的新手。我正在测试 SqlServerDsc 模块中的 SqlServiceAccount 资源,但无法弄清楚如何使用 PSCredential 类。我的目标是在变量中有凭据,但无法弄清楚如何正确执行此操作。我查看了示例并阅读了 psm1 以获取其 github 上的资源,但仍然丢失了。 这是我用来测试它的代码,密码和其他信息在另一个脚本中,在这个脚本的底部被调用。提示我输入凭据的窗口正在弹出,但我希望将我的凭据放在变量中以填充它。
Configuration SQLInstall
{param (
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]
$PackagePath,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]
$ServiceAccountCredential
)
Import-DscResource –ModuleName PSDesiredStateConfiguration
Import-DSCResource -ModuleName ComputerManagementDsc
Import-DSCResource -ModuleName SqlServerDsc
Node $AllNodes.where{ $_.Role.Contains("SQLENGINE") }.NodeName
{
Log ParamLog
{
Message = "Running SQLInstall. PackagePath = $PackagePath"
}
# Password info here
$password = $using:Node.Service4SQLPassword | ConvertTo-SecureString -asPlainText -Force
$username = $using:Node.Service4SQLAccount
$Credential = New-Object System.Management.Automation.PSCredential($username,$password)
SqlServiceAccount SetServiceAccount_DatabaseEngine
{
ServerName = $Node.NodeName
InstanceName = 'MSSQLSERVER'
ServiceType = 'DatabaseEngine'
ServiceAccount = $ServiceAccountCredential
RestartService = $true
Force = $true
DependsOn = "[Script]InstallSQLServer"
}
SqlServiceAccount SetServiceAccount_SQLServerAgent
{
ServerName = $Node.NodeName
InstanceName = 'MSSQLSERVER'
ServiceType = 'SQLServerAgent'
ServiceAccount = $ServiceAccountCredential
RestartService = $true
Force = $true
DependsOn = "[Script]InstallSQLServer"
}
SqlServiceAccount SetServiceAccount_IntegrationServices
{
ServerName = $Node.NodeName
InstanceName = 'MSSQLSERVER'
ServiceType = 'IntegrationServices'
ServiceAccount = $ServiceAccountCredential
RestartService = $true
Force = $true
DependsOn = "[Script]InstallSQLServer"
}
}}
SQLInstall -ConfigurationData C:\PowerShell_UserScripts\MyServerData.psd1 `
【问题讨论】:
标签: sql-server powershell dsc