私はDSCから呼び出されるCMDの資格情報をどのように参照できるのだろうかと思っていました。 これは展開しようとしている構成ですが、資格情報を受信しません。DSCから呼び出されるCMDの参照資格情報
configuration SQLCMD
{
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullorEmpty()]
[PSCredential]
$Credential
)
Import-DscResource -ModuleName xSqlServer
Node localhost
{
LocalConfigurationManager
{
ConfigurationMode = 'ApplyOnly'
RebootNodeIfNeeded = $true
ActionAfterReboot = 'ContinueConfiguration'
AllowModuleOverwrite = $true
}
Script DeployDBmoveTempDB
{
SetScript = {
$SourceFile = 'C:\DatabaseTest.dacpac'
$TargetServerName = 'localhost'
$TargetDatabaseName = 'TestDB1'
$databaseSizeSQLCMD = '200MB'
$databaseLogSizeSQLCMD = '20MB'
$tempdbSizeSQLCMD = '1900MB'
$tempdbLogSizeSQLCMD = '1900MB'
trap {
Write-Error $_
Exit 1
}
$args = @('/Action:Publish'
,"/SourceFile:$SourceFile"
,"/TargetServerName:$TargetServerName"
,"/TargetUser:$Credential.UserName"
,"/TargetPassword:$Credential"
,"/TargetDatabaseName:$TargetDatabaseName"
,"/v:databaseSizeSQLCMD=$databaseSizeSQLCMD"
,"/v:databaseLogSizeSQLCMD=$databaseLogSizeSQLCMD"
,"/v:tempdbSizeSQLCMD=$databaseSizeSQLCMD"
,"/v:tempdbLogSizeSQLCMD=$databaseLogSizeSQLCMD"
,'/p:BlockOnPossibleDataLoss=false'
)
try {
& "C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin\SqlPackage.exe" $args
}
catch {
Write-Host $_ ;
}
}
TestScript = {
Test-Path D:\TestDB1_primary.mdf
}
GetScript = { <# This must return a hash table #> }
}
}
}
ただし、以下の設定が正常に動作します:生成されたMOF内の文字列として
configuration SQLCMD
{
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullorEmpty()]
[PSCredential]
$Credential
)
Import-DscResource -ModuleName xSqlServer
Node localhost
{
LocalConfigurationManager
{
ConfigurationMode = 'ApplyOnly'
RebootNodeIfNeeded = $true
ActionAfterReboot = 'ContinueConfiguration'
AllowModuleOverwrite = $true
}
Script DeployDBmoveTempDB
{
SetScript = {
$ErrorActionPreference = "Stop"
$SourceFile = 'C:\DatabaseTest.dacpac'
$TargetServerName = 'localhost'
$user_name = 'mySqlAdmin'
$user_pwd = 'blabla'
$TargetDatabaseName = 'TestDB1'
$databaseSizeSQLCMD = '200MB'
$databaseLogSizeSQLCMD = '20MB'
$tempdbSizeSQLCMD = '1900MB'
$tempdbLogSizeSQLCMD = '1900MB'
trap {
Write-Error $_
Exit 1
}
$args = @('/Action:Publish'
,"/SourceFile:$SourceFile"
,"/TargetServerName:$TargetServerName"
,"/TargetUser:$user_name"
,"/TargetPassword:$user_pwd"
,"/TargetDatabaseName:$TargetDatabaseName"
,"/v:databaseSizeSQLCMD=$databaseSizeSQLCMD"
,"/v:databaseLogSizeSQLCMD=$databaseLogSizeSQLCMD"
,"/v:tempdbSizeSQLCMD=$databaseSizeSQLCMD"
,"/v:tempdbLogSizeSQLCMD=$databaseLogSizeSQLCMD"
,'/p:BlockOnPossibleDataLoss=false'
)
try {
& "C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin\SqlPackage.exe" $args
}
catch {
Write-Host $_ ;
}
}
TestScript = {
Test-Path D:\TestDB1_primary.mdf
}
GetScript = { <# This must return a hash table #> }
}
}
}
https://github.com/PowerShell/xDatabase? – 4c74356b41
そのような外部コマンドに資格情報を渡すことはできません。外部コマンドが最初にPowerShellオブジェクトについて何かを知っているだけでなく、文字列の '$ Credential'は、資格証明オブジェクトの文字列表現に展開されます。文字列' 'System.Management.Automation.PSCredential ' '。信任状オブジェクトからユーザー名とパスワードを展開し、それを外部コマンドに渡す必要があります。 –