Closed BladeFireLight closed 9 years ago
You can use a key of 'ComputerName\UserName'
, and it should work.
$configData.Credentials.computername\username At line:1 char:37 $configData.Credentials.computername\username ~~~~~~~~~ Unexpected token '\username' in expression or statement. CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException FullyQualifiedErrorId : UnexpectedToken
$configData.Credentials.'computername\username' works at the console but not in the configuration script. it just gives me this in the .mof
State = "Running"; Credential = NULL;
That also does not work so well if I have multiple computers with the same local admin account.
say SiteA has 20 computers with one local admin password and SiteB has 10 computers with a different password. I cant use computername\username in that situation.
Well I figured out, this code works. But does not solve the above shared in small groups administrator account problem In the DSC_Configuration\Services file
ServiceSettings = @{ Service =@( @{ Name = 'scsm' CredName = 'domain\logagent' DependsOn = '[file]LogRythemConfigFile' StartupType = 'Automatic' State = 'Running' } ) }
In the Config called by Invoke-DscBuild
#region ### Service Settings ### if (Test-DscConfigurationPropertyExists -Node $Node -PropertyName ServiceSettings) { $Services = @( Resolve-DscConfigurationProperty -Node $Node -PropertyName ServiceSettings\Service -MultipleResultBehavior AllValues ) foreach ($Service in $Services) { if ($Service['BuiltInAccount']) { Service $Service['Name'] { Name = $Service['Name'] BuiltInAccount = $Service['BuiltInAccount'] DependsOn = $Service['DependsOn'] StartupType = $Service['StartupType'] State = $Service['State'] } } else { Service $Service['Name'] { Name = $Service['Name'] Credential = $ConfigurationData.Credentials."$($Service['CredName'])" DependsOn = $Service['DependsOn'] StartupType = $Service['StartupType'] State = $Service['State'] } } } } #endregion
Well, in the tooling module, the key is the username of the PSCredential. However, there's nothing stopping you from just making up names to go in there, and replacing them at execution time with whatever's appropriate. For example, if we're talking about local admin accounts, then you could just strip out anything before the first backslash of the username, something along these lines:
ServiceSettings = @{
Service =@(
@{
Name = 'scsm'
CredName = 'SiteAGroup\Administrator'
DependsOn = '[file]LogRythemConfigFile'
StartupType = 'Automatic'
State = 'Running'
}
)
}
$cred = $ConfigurationData.Credentials."$($Service['CredName'])"
$cred = New-Object pscredential(($cred.UserName -replace '^[^\\]*\\'), $cred.Password)
Service $Service['Name']
{
Name = $Service['Name']
Credential = $cred
DependsOn = $Service['DependsOn']
StartupType = $Service['StartupType']
State = $Service['State']
}
I'm using the Development version. Is it possible to have different names for credentials besides the user-name. so I have a number of computers with different local admin accounts I need the keys under $ConfigurationData.Credentials to be different. however as it is, whatever I add as the username also becomes the key.