Open JP-MB opened 1 year ago
Use the built-in parameter PSDscRunAsCredential
to the credentials that have permission to read the path: https://learn.microsoft.com/en-us/powershell/dsc/configurations/runasuser?view=dsc-1.1
thks a lot for your reply, but how to code under MountImage . it doesn't seem to be an available parameter
I try something like
Node $Node
{
{PsDscRunAsCredential = Get-Credential}
....
but no impact and credential required at console .
You have to change Get-Credential
, that is just a simple example. Instead you pass a password as a parameter (PSCredential) to the configuration so that the password is compiled into the MOF file (the configuration run by Start-DscConfiguration). By passing this credential the resource is run as that user, that user need the correct permissions on the share (share permission and file system permission).
For testing you can pass plain text password in the compiled configuration. For production you should use certificate to encrypt the password. See DSC documentation how to encrypt credentials.
The parameter is built-in in DSC and supported by LCM.
MountImage SQL2019
{
ImagePath = $Drive
DriveLetter = 'S'
#Ensure = 'Present'
Access = 'ReadOnly'
PSDscRunAsCredential = $MyCredential
}
I have PS C:\Users\a-millionje\Documents\DSC\SQLInstall> $credentials
UserName Password
a-millionje System.Security.SecureString
PS C:\Users\a-millionje\Documents\DSC\SQLInstall> $configData = @{AllNodes = @(@{NodeName= 'localhost';PsDscAllowPlainTextPassword = $true} )}
PS C:\Users\a-millionje\Documents\DSC> ./SQLInstall.ps1 -MyCredential $credentials $configData
cmdlet SQLInstall at command pipeline position 1 Supply values for the following parameters: Node: NLVCP1842D
Directory: C:\Users\a-millionje\Documents\DSC\SQLInstall
Mode LastWriteTime Length Name
-a---- 06/03/2023 15:28 4672 NLVCP1842D .mof
with SQLINSTALL source:
Configuration SQLInstall { param( [parameter(mandatory=$true)][string]$Node, [PSCredential]$MyCredential )
Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
Import-DSCResource -ModuleName StorageDsc #For ISO-mounting
Import-DscResource -ModuleName sqlserverdsc
Node $Node
{
$Drive='\\D1.cougar.ms.lvmh\DfsLvm\Apps\Soft_Nt\Ent_Core_2019_64Bit_English'
MountImage SQL2019
{
ImagePath = $Drive
DriveLetter = 'S'
Ensure = 'Present'
Access = 'ReadOnly'
PsDscRunAsCredential = $MyCredential
}
WaitForVolume WaitForSQL2019
{
DriveLetter = 'S'
RetryIntervalSec = 5
RetryCount = 10
}
WindowsFeature 'NetFramework45'
{
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
SqlSetup 'InstallDefaultInstance'
{
InstanceName = 'TEST'
Features = 'SQLENGINE'
SourcePath = 'S:\'
SQLSysAdminAccounts = @('a-xxxxxxx','a-xxxxxxx')
DependsOn = '[WindowsFeature]NetFramework45'
}
}
} SQLInstall
but got issue when run config
PS C:\Users\a-millionje\Documents\DSC\SQLInstall> Start-DscConfiguration -path "." -verbose -wait
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'. The WS-Management service cannot process the request. The WMI service returned an 'access denied' error.
VERBOSE: Operation 'Invoke CimMethod' complete. VERBOSE: Time taken for configuration job to complete is 0.167 seconds
Apparently it doesn't use my credential ; no ?
Make sure the account you use in the PSDscRunAsCredential is allowed to run resources. The account need specific rights on the node. Don't remember which ones now.
The right can be found here https://learn.microsoft.com/en-us/powershell/dsc/configurations/runasuser
Then make sure to run Start-DscConfiguration as elevated user.
Hello thks for your support After investigating I 've change a little bit my source MOF with teh follow:
Configuration SQLInstall { param( [parameter(mandatory=$true)][string]$Node, [parameter(mandatory=$true)][PScredential] $MyCred )
Import-DscResource –ModuleName PSDesiredStateConfiguration
Import-DSCResource -ModuleName StorageDsc #For ISO-mounting
Import-DscResource -ModuleName sqlserverdsc
Node $Node
{
#$Drive='\\D1.cougar.ms.lvmh\DfsLvm\Apps\Soft_Nt\_soft\Microsoft\SQL_server\SQL Server 2019\Ent_Core_2019_64Bit_English'
$Drive='C:\Users\a-millionje\Documents\DSC\SW_DVD9_SQL_Svr_Enterprise_Edtn_2019Dec2019_64Bit_English_MLF_X22-22247.ISO'
MountImage SQL2019
{
ImagePath = $Drive
DriveLetter = 'S'
Ensure = 'Present'
Access = 'ReadOnly'
PsDscRunAsCredential = $MyCred
}
WaitForVolume WaitForSQL2019
{
DriveLetter = 'S'
RetryIntervalSec = 5
RetryCount = 10
}
WindowsFeature 'NetFramework45'
{
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
SqlSetup 'InstallDefaultInstance'
{
InstanceName = 'TEST'
Features = 'SQLENGINE'
SourcePath = 'S:\'
SQLSysAdminAccounts = @('a-millionje','a-akella')
DependsOn = '[WindowsFeature]NetFramework45'
}
}
$mydata= @{ AllNodes = @( @{ NodeName = "*" PSDscAllowDomainUser = $true PSDscAllowPlainTextPassword = $true } )
} }
SQLInstall
Then use following command with configurationdata to generatare MOF :
PS C:\Users\a-millionje\Documents\DSC> .\SQLInstall4.ps1 -configurationdata $mydata
But finally it doesn't want to generate it arguing security message
PS C:\Users\a-millionje\Documents\DSC> .\SQLInstall4.ps1 -configurationdata $mydata
cmdlet SQLInstall at command pipeline position 1 Supply values for the following parameters: Node: NLVCP1843D MyCred ConvertTo-MOFInstance : System.InvalidOperationException error processing property 'PsDscRunAsCredential' OF TYPE 'MountImage': Converting and storing encrypted passwords as plain text is not recommended. For more information on securing credentials in MOF file, please refer to MSDN blog: http://go.microsoft.com/fwlink/?LinkId=393729 At C:\Users\a-millionje\Documents\DSC\SQLInstall4.ps1:14 char:2
+ CategoryInfo : InvalidOperation: (:) [Write-Error], InvalidOperationException
+ FullyQualifiedErrorId : FailToProcessProperty,ConvertTo-MOFInstance
WARNING: It is not recommended to use domain credential for node 'NLVCP1843D'. In order to suppress the warning, you can add a property named 'PSDscAllowDomainUser' with a value of $true to
your DSC configuration data for node 'NLVCP1843D'.
Compilation errors occurred while processing configuration 'SQLInstall'. Please review the errors reported in error stream and modify your configuration code appropriately.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3917 char:5
+ CategoryInfo : InvalidOperation: (SQLInstall:String) [], InvalidOperationException
+ FullyQualifiedErrorId : FailToProcessConfiguration
does it really possible to do it ?
Your passing in a parameter to the script when the parameter is in the configuration.
Without really knowing want you doing, I think you probably need to do
# dot-source the script
. .\SQLInstall4.ps1
# pass the parameters to the configuration
SQLInstall -Node 'localhost' -MyCred $credentials -ConfigurationData $mydata
Hello I do what I read here https://learn.microsoft.com/en-us/powershell/dsc/configurations/configdata?view=dsc-1.1
It says to use the configuration in the same file but you are passing the configuration from outside the file?
No I pass in the same file Configuration SQLInstall { param( [parameter(mandatory=$true)][string]$Node, [parameter(mandatory=$true)][PScredential] $MyCred )
Import-DscResource –ModuleName PSDesiredStateConfiguration
Import-DSCResource -ModuleName StorageDsc #For ISO-mounting
Import-DscResource -ModuleName sqlserverdsc
Node $Node
{
#$Drive='\\D1.cougar.ms.lvmh\DfsLvm\Apps\Soft_Nt\_soft\Microsoft\SQL_server\SQL Server 2019\Ent_Core_2019_64Bit_English'
$Drive='C:\Users\a-millionje\Documents\DSC\SW_DVD9_SQL_Svr_Enterprise_Edtn_2019Dec2019_64Bit_English_MLF_X22-22247.ISO'
MountImage SQL2019
{
ImagePath = $Drive
DriveLetter = 'S'
Ensure = 'Present'
Access = 'ReadOnly'
PsDscRunAsCredential = $MyCred
}
WaitForVolume WaitForSQL2019
{
DriveLetter = 'S'
RetryIntervalSec = 5
RetryCount = 10
}
WindowsFeature 'NetFramework45'
{
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
SqlSetup 'InstallDefaultInstance'
{
InstanceName = 'TEST'
Features = 'SQLENGINE'
SourcePath = 'S:\'
SQLSysAdminAccounts = @('a-millionje','a-akella')
DependsOn = '[WindowsFeature]NetFramework45'
}
}
$mydata= @{ AllNodes = @( @{ NodeName = "*" PSDscAllowDomainUser = $true PSDscAllowPlainTextPassword = $true } )
} }
SQLInstall
Change SqlInstall in the end to:
SQLInstall -Node 'localhost' -MyCred $credentials -ConfigurationData $mydata
Hello same result . Compile is KO
Problem description
I face issue Acces Denied when launch Start-Dsc
Have u got any idea about this deny ? Try with my authorised credentail , but same issue . Try to give computer authorize on DVD, but impossible
Verbose logs
DSC configuration
Suggested solution
Try to give Read access to DVD to computer . But impossible
Operating system the target node is running
PowerShell version and build the target node is running
StorageDsc version